j'ai les modèles et les associations suivantes:association par has_many et multiple appartient à
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
Je dois pouvoir appeler user.albums et user.artists sur une base régulière. Est-ce que l'option la plus efficace pour créer has_and_belongs_to_many associations entre User et Artist/Album?
Il semble qu'il devrait y avoir un meilleur moyen mais je n'ai encore rien trouvé.
Wow. PET de cerveau. Merci – mrabin