-1
je suit les associationsRails: requête pour a beaucoup à travers des associations
class Post < ActiveRecord::Base
has_many :categorizations
has_many :categories, through: :categorizations
class Categorization < ActiveRecord::Base
belongs_to :category
belongs_to :post
end
class Category < ActiveRecord::Base
has_many :categorizations
has_many :posts, through: :categorizations
end
Pour un utilisateur, je reçois tous les postes,
@posts = current_user.posts
Je besoin de toutes les catégories associées à @posts. Donc, j'ai besoin de quelque chose comme ça
@categories = @posts.categories
Alors, comment puis-je obtenir les catégories de messages associés.