forrest lyman Fri Jan 28 09:45:31 -0500 2011

Subject: query object

have you guys considered creating a query object as an alternative option for composing select statements? At first I did not like the way ZF did this, but I think it makes complicated queries much easier to read and compose dynamically when compared to array notation.

Maybe something like this:

// find users created within the last month
$result = User::find(Query::select()
                            ->where('date_created > ?', $oneMonthAgo)
                            ->order('name DESC'));

Kien La Fri Feb 04 17:56:24 -0500 2011

Yes, would be nice but not in our immediate plans.

Jono B Thu Feb 10 20:10:10 -0500 2011

+1 from me on this as well.

For simplicity of writing, CodeIgniter's AR syntax ( takes a lot of beating.

forrest lyman Mon Feb 14 14:33:01 -0500 2011

I have a very simplistic version of this working. At this point it is more of a proof of concept, but it does work:

$finder = Person::finder()->where('age > ?', 18)
->order('age DESC');
$adults = Person::all($finder);

I did need to overload a couple ActiveRecord\Model methods, creating my own layer on top, but we could probably figure out a way around that. The issue was getting the ActiveRecord\Model class to treat the finder like an array (it does implement array access).

Is this something you would like to check out?