User
has_many :posts
has_many :post_tags, :through => :posts
PostTag
belong_to :post
belongs_to :tag
scope :distincttag, :select => ('distinct post_tags.tag_id')
avec Rails 3.0.4, je reçois SQL invalide: SELECT post_tags *, tag_id distinct ...rails - à l'aide: sélectionnez (distincte) avec: has_many: par association produit SQL non valide
à. au moins une autre personne a connu le même problème: http://www.ruby-forum.com/topic/484938
fonctionnalité ou un bug?
grâce
OK, jamais l'esprit, il ne fonctionne . En d'autres termes, créer une portée sous PostTag fonctionne. Ce qui ne marche pas, cependant, c'est de chaîner un ".select": someuser.post_tags.select ('distinct tag_id') entraînera l'erreur ci-dessus. Ne pas "select" remplacer le select implicite dans la jointure/association? – avioing
'@ user.post_tags.uniq.pluck (: tag_id)' pourrait vous obtenir ce que vous voulez – bdares