0
我有以下型號和協會:協會通過的has_many和多屬於
class User < ActiveRecord::Base
has_and_belongs_to_many :songs
end
class Song < ActiveRecord::Base
has_and_belongs_to_many :users
belongs_to :album
delegate :artist, :to => :album, :allow_nil => true
end
class Album < ActiveRecord::Base
has_many :songs
belongs_to :artist
end
class Artist < ActiveRecord::Base
has_many :albums
has_many :songs, :through => :albums
end
我需要能夠調用user.albums和user.artists定期。是用戶和歌手/專輯之間創建has_and_belongs_to_many關聯的最有效選擇嗎?
看起來應該有更好的方法,但我還沒有找到任何東西。
哇。腦屁。謝謝 – mrabin