模型關聯 class User < ActiveRecord::Base
has_many :boards
has_many :cards, through: :boards
end
class Board < ActiveRecord::Base
belongs_to :user
has_many :cards
end
class Card <
我有一個類Test, Question, Testquestion通過has_many through class Test
has_many :testquestions
has_many :questions, through: :testquestions
end
class Question
has_many :testquestions
ha
我正在創建一個音樂應用程序,用戶可以將歌曲添加到播放列表中。我通過關聯創建了一個has_many,以便將「playlist_songs」添加到播放列表中,而不是「歌曲」 以下是一些相關的代碼,以便爲您提供一個更好的主意。 playlist_song.rb class PlaylistSong < ActiveRecord::Base
belongs_to :playlist
b
我在我的食譜模型連接到我的標籤模式使得許多一對多/有一對多,通過關係: class Tag < ActiveRecord::Base
has_many :taggings
has_many :recipes, through: :taggings
end
class Tagging < ActiveRecord::Base
belongs_to :tag