On Jun 6, 4:22 pm, danimashu <daniel.madrid.re...@gmail.com> wrote:
> Hello,
>
> I've a usually structure with Post has_many Tags through Taggings. All
> works well and clean. But I'm having problems with the next scope on
> Post:
>
> scope :tagged, lambda {|tag_id| joins(:taggings).where(:taggings =>
> {:tag_id => tag_id}) }
>
> All works fine for call of only one Tag like: Post.tagged("sport") .
> The problem comes when you want to show the adverts that have any tag
> OR other, like well: Post.tagged(%w{sport people}). Then, the INNER
> JOIN do that I may get repeated results of Post. For example, if I may
> have two Post with "sport" and "people" tag each one, with the
> previous call, I would get 4 results.

Haven't tried it, but maybe grouping on posts.id would do the right
thing?

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to