[CDBI] Re: has_many relationships and order_by

Matt S Trout dbix-class at trout.me.uk
Thu Dec 15 12:54:06 GMT 2005


On Wed, Dec 14, 2005 at 04:43:49PM -0500, Edward J. Sabol wrote:
> > I've encountered a problem with has_many relationships in Class::DBI, after
> > upgrading from 0.96 to 3.0.12. Once upon a time, calling:-
> >
> >      my $iter = $object->children({order_by => "name"})
> >
> > where "children" is a "has_many" relationship would work nicely, and you
> > would get a list/iterator back which would contain your data, all nicely
> > sorted.
> >
> > Now, however, I get an error stating that:- "order_by is not a column of
> > Person"
> >
> > I'm just wondering if this has been changed on purpose, or whether to
> > report it as a bug. I can send a test case (using DBD::SQLite2) if
> > needed.
> 
> I'm guessing it's probably an unintended side effect of this line of code in
> _hm_run_search() in Class::DBI::Relationship::HasMany:
> 
>     @search_args = %{ $search_args[0] } if ref $search_args[0] eq "HASH";
> 
> It's not clear to my why that line was added.

In order to deal with

$obj->has_many_method({ foo => 1 });

instead of

$obj->has_many_method(foo => 1);

Class::DBI in and of itself doesn't have support for ordering etc. so it
doesn't handle search attrs; not being able to pass attributes to has_many
searches and similar, such as

$obj->has_many_method({ foo => 1 }, { prefetch => 'some_might_have' });

has been a substantial driver for people migrating from Class::DBI::Sweet
to DBIx::Class, where this sort of feature set was designed into the core
from the start (advocacy though this is, I'm pretty much directly quoting
a number of my users here).

-- 
     Matt S Trout       Offering custom development, consultancy and support
  Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +




More information about the ClassDBI mailing list