Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Katha (and related) Models + Migration #59

Merged
merged 4 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/chapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ class Chapter < ApplicationRecord
belongs_to :book
has_many :chhands, :dependent => :destroy
has_many :pauris, :dependent => :destroy
has_many :tuks, :through => :pauris
has_many :chapter_kathas, :dependent => :destroy
has_many :kathas, :through => :chapter_kathas
end
6 changes: 6 additions & 0 deletions app/models/chapter_katha.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class ChapterKatha < ApplicationRecord
belongs_to :katha
belongs_to :chapter
end
5 changes: 5 additions & 0 deletions app/models/giani.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class Giani < ApplicationRecord
has_many :kathas, :dependent => :destroy
end
7 changes: 7 additions & 0 deletions app/models/katha.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class Katha < ApplicationRecord
belongs_to :giani
has_many :chapter_kathas, :dependent => :destroy
has_many :chapters, :through => :chapter_kathas, :dependent => :destroy
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

class CreateKathasAndGianisAndChapterKathas < ActiveRecord::Migration[7.0]
def up
create_table :gianis do |t|
t.string :name, :null => false
t.string :artwork_url

t.timestamps
end

create_table :kathas do |t|
t.references :giani, :null => false, :foreign_key => true
t.string :title
t.string :public_url
t.string :soundcloud_url
t.integer :year

t.timestamps
end

create_table :chapter_kathas do |t|
t.references :chapter, :null => false, :foreign_key => true
t.references :katha, :null => false, :foreign_key => true

t.timestamps
end

# Seeding Gianis
Giani.create!([
{ :id => 1, :name => 'Giani Harbhajan Singh Dhudike' },
{ :id => 2, :name => 'Nihang Giani Sher Singh Ambala' },
{ :id => 3, :name => 'Sant Giani Inderjit Singh Raqbewale' },
{ :id => 4, :name => 'Bhai Sukha Singh UK' },
{ :id => 5, :name => 'The Suraj Podcast' }
])
end

def down
drop_table :gianis
drop_table :kathas
drop_table :chapter_kathas
end
end
34 changes: 32 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.