
Finders lose relational information across M:M relationships, and as a result fail to group & return properly.
Reported by Ted Han (knowtheory) | July 3rd, 2009 @ 07:31 AM | in 0.10.2
example:
@presentations = 10.of{ Presentation.gen }
@presentations.each_with_index do |presentation,index|
presentation.tag_list = %w(a b c d e f g h i j)[0+1..index].join(" ")
presentation.save
end
so:
>> @presentations.map{ |p| p.tags.map{ |t| t.id }}
=> [[], [2 ], [2, 3], [2, 3, 4], [2, 3, 4, 5], [2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7], [2, 3, 4, 5, 6, 7, 8], [2, 3, 4, 5, 6, 7, 8, 9], [2, 3, 4, 5, 6, 7, 8, 9, 10]]
However:
>> Presentation.all(:id => @presentations.map{|p| p.id }).map{ |p| p.tags.map{ |t| t.id } }
=> [[2 ], [3 ], [4 ], [5 ], [6 ], [7 ], [8 ], [9 ], [10 ], []]
Same thing happens if you just do Presentation.all.map{ |p| p.tags.map{ |t| t.id }}, but the above example better indicates how incorrect the result is.
As a result,
>> @presentations.map{ |p| p.tags } == Presentation.all(:id => @presentations.map{ |p| p.id }).map{ |p| p.tags }
=> false
Why is this happening? Well the following DM query:
>> Presentation.all(:id => @presentations.map{|p| p.id }).map{ |p| p.tags.map{ |t| t.id } }
Produces the SQL below:
SELECT "tags"."id", "tags"."name" FROM "tags"
INNER JOIN "presentation_taggables" ON "tags"."id" = "presentation_taggables"."tag_id"
INNER JOIN "presentations" ON "presentation_taggables"."presentation_id" = "presentations"."id"
WHERE "presentation_taggables"."presentation_id" IN (2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
GROUP BY "tags"."id", "tags"."name"
ORDER BY "tags"."id"
The issue at hand is that the query should GROUP BY
"tags"."id", "tags"."name",
"presentation_taggables"."presentation_id"
not just by
"tags"."id", "tags"."name"
Comments and changes to this ticket
-
Ted Han (knowtheory) July 3rd, 2009 @ 07:36 AM
Had to add some spaces into the arrays, because lighthouse is too stupid to realize that arrays of numbers (e.g. [2]) inside a code block isn't one of its changeset annotations
-
Ted Han (knowtheory) July 3rd, 2009 @ 07:41 AM
Oh and worse yet, i forgot to mention this:
>> Presentation.all(:id => @presentations.map{ |p| p.id }).map{ |p| p.taggings.map{|t| t.tag}} == Presentation.all(:id => @presentations.map{ |p| p.id }).map{ |p| p.tags } => false
-
Ted Han (knowtheory) July 4th, 2009 @ 07:03 AM
If you check out my dm-specs repo, there's a test in there now that indicates the failure case.
http://github.com/knowtheory/dm-specs/blob/master/specs/spec_many_t...
-
Dan Kubb (dkubb) July 10th, 2009 @ 02:56 PM
- State changed from unconfirmed to accepted
-
Dan Kubb (dkubb) October 4th, 2009 @ 09:33 PM
- Tag changed from 0.10.0, many-to-many, sel, through to many-to-many, sel, through
- Milestone changed from 0.10.0 to 0.10.2
[project:id#20609 not-tagged:"0.10.0" milestone:id#51895 bulk edit command]
-
Dan Kubb (dkubb) November 10th, 2009 @ 02:25 AM
- State changed from accepted to resolved
Given that the dm-specs all pass with edge dm-core I am marking this ticket as resolved.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »