[Dbix-class] Duplicate me.id in WHERE clause of simple query

Alan Humphrey alan.humphrey at comcast.net
Tue Jan 25 17:49:56 GMT 2011

Coincidentally, I just saw this behavior.

The trick seems to be setting up a belongs_to relationship where the relationship name is the name of the foreign key:

__PACKAGE__->belongs_to( 'order_id', 'BirdWeb::BirdWebSchema::Orders');


__PACKAGE__->belongs_to( 'order_id', 'BirdWeb::BirdWebSchema::Orders', 'order_id');

Then use the relationship name:


If you prefetch the relationship there's no problem.  If you use a different name for the relationship there's no problem.

And, as Winni originally reported, the problem is an extra 'me.id' in the generated SQL: 

SELECT me.id, me.order_scientific_name, me.order_common_name, me.order_description, me.order_navigation_name, me.taxonomic_order, me.species_worldwide, me.species_north_america, me.species_washington, me.families_worldwide, me.families_north_america, me.families_washington FROM orders me WHERE ( ( me.id = '9' AND me.id = '9' ) )

Hope that helps.

- Alan

> -----Original Message-----
> From: Winfried Neessen [mailto:winfried at neessen.net]
> Sent: Tuesday, January 25, 2011 2:55 AM
> To: user and developer list
> Subject: Re: [Dbix-class] Duplicate me.id in WHERE clause of simple
> query
> Hi Peter,
> Peter Rabbitson schrieb:
> > So can you repeat your question with a coherent, reproducible problem
> > description? I tried to trigger what you are seeing and I can't.
> Which
> > either means I am missing something, or that you forgot to mention
> yet
> > another crucial detail.
> >
> > Please show us the whole code[1] :)
> I understand that it makes it easier for you to see the whole code, and
> I appreciate
> the work of everybody who tried to help me with my problem, but due to
> copyright
> restrictions I cannot post the whole code on a public mailing list-
> sorry :-/
> As my "problem" isn't a real problem but more like a cosmetical fnord
> (my code is
> working perfectly fine, I was just wondering why the debug output
> produces
> "WHERE ( ( me.id = 1 AND me.id = 1 ) )" constructs), I will just leave
> it as it is and
> go on with my work.
> Again thanks for your work and time you guys spent to help me- much
> appreciated.
> Winni
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-
> class at lists.scsys.co.uk

More information about the DBIx-Class mailing list