Skip Menu |

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 20309
Status: rejected
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: engel [...] node.ch
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.06000
Fixed in: (no value)



Subject: Prefetch does not work for has_many relationship (because INNER JOIN is used)
Consider the following example: $schema->resultset('artist')->search({ }, { prefetch => ['CD']}); Now, if there are no CD's of a given artist, this artist would not be returned. This behavior is inconsistent, since $schema->resultset('artist')->search({ }); would have returned this artist. Adding a "prefetch" should only affect the performance, but not the logic of the returned data. This problem might be resolved by using a LEFT OUTER JOIN instead of an INNER JOIN. Thank you for maintaining the DBIx::Class --- this is a great module! Best, Hansres
On Wed Jul 05 19:22:17 2006, guest wrote: Show quoted text
> Consider the following example: > $schema->resultset('artist')->search({ }, { prefetch => ['CD']}); > > Now, if there are no CD's of a given artist, this artist would not be > returned.
Yes it would, DBIx::Class defaults to a LEFT join on a has_many relationship. Marking this ticket as rejected; if you've overriden the join type that was your decision, if not it already behaves as you requested. If you're unsure about usage please mail the list. Show quoted text
> Thank you for maintaining the DBIx::Class --- this is a great module!
Ta :)
Show quoted text
> > Consider the following example: > > $schema->resultset('artist')->search({ }, { prefetch => ['CD']});
> > if you've overriden the join type that > was your decision, if not it already behaves as you requested.
Thank you for the explanation! However, I am not sufficiently experienced with DBIx::Class to understand your statement. Is your point that prefetch indirectly overrides the join type? And that therefore the API user must explicitly specify how he wants to join? So the crucial point is that an API user must understand that prefetch (indirectly) modifies the join behavior and that therefore things do not work as naively expected. Well, then this is not what I would have expected from an otherwise great API... Cheers, Hansres
On Fri Jul 07 18:26:24 2006, guest wrote: Show quoted text
> > > Consider the following example: > > > $schema->resultset('artist')->search({ }, { prefetch => ['CD']});
> > > > if you've overriden the join type that > > was your decision, if not it already behaves as you requested.
> > Thank you for the explanation! However, I am not sufficiently > experienced with DBIx::Class to understand your statement. Is your > point that prefetch indirectly overrides the join type? And that > therefore the API user must explicitly specify how he wants to join?
No. The point is that a has_many relationship, on being set up, defaults to using a join type of LEFT automatically. Thus the behavioural change you're aking for is already implemented, and has been for some time. Show quoted text
> So the crucial point is that an API user must understand that prefetch > (indirectly) modifies the join behavior and that therefore things do not > work as naively expected.
No, not at all - see my explanation above. If you're still confused *please* bring this to the list - this is *not* a bug and RT tickets are not the place for general discussion.