0
j'ai obtenu cette « requête »requête d'enregistrement actif avec comprend ne comprend pas
@product_collections = ProductCollection.
#includes(:products). #does not do anything
joins(:products). #this at least gives me the products (in articles table)
group("tags.id").
where("articles.category_id = ?", @category.id).
where("articles.available = ?", true).
order('tags.name asc')
ce produit les éléments suivants sql
SELECT "tags".* FROM "tags"
INNER JOIN "article_taggings" ON "tags"."id" = "article_taggings"."tag_id"
INNER JOIN "articles" ON "articles"."id" = "article_taggings"."article_id"
WHERE ("tags"."type" = 'ProductCollection')
AND (articles.category_id = 1)
AND (articles.available = 't')
GROUP BY tags.id
ORDER BY tags.name asc
comment pourrais-je gérer pour obtenir les produits dans un (ou seulement une seconde) aller?
Modèles:
class Article < ActiveRecord::Base
has_many :article_taggings
has_many :tags, :through => :article_taggings
end
class Product < Article
belongs_to :category
has_many :product_collections, :through => :article_taggings, :source => :tag
end
class ArticleTagging < ActiveRecord::Base
belongs_to :article
belongs_to :tag
end
class Tag < ActiveRecord::Base
has_many :article_taggings
has_many :articles, :through => :article_taggings
has_and_belongs_to_many :web_pages
end
class ProductCollection < Tag
has_many :products, :through => :article_taggings, :source => :article
end
Pouvez-vous poster les modèles qui sont impliqués dans cette requête? –
Ils sont là, désolé pour le retard, je n'ai pas été informé de votre commentaire :( – Jan