[Rails] Re: Avoiding repeated results

2011-06-07 Thread danimashu
> Haven't tried it, but maybe grouping on posts.id would do the right > thing? > > --Matt Jones Hello Matt, thanks for the answer. I've try it and it works fine except when you call to "count" method later. I've solve it well: scope :finded, lambda {|id| where(:id => id)} scope :tagged, lambda {|

[Rails] Re: Avoiding repeated results

2011-06-07 Thread Matt Jones
On Jun 6, 4:22 pm, danimashu 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}) }

[Rails] Re: Avoiding repeated results

2011-06-07 Thread danimashu
I'm trying to use "select('DISTINCT *')" but it doesn't work. Sure, de INNER JOIN between Post and Tagging result of table that all rows are distinct. If we supost the next: Posts Table ID TITLE 1"Foo" 2"FooFaa" TAGGINGS Table ID POST_ID TAG_ID 1 11 1