模型关联 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