rudiedirkx/Rudie-on-wheels — Issue #29: Super simple query builder for in Model::_query
Author: rudiedirkx
Created: 2011-10-27 15:37:59+00:00
State: open

Current content:

return 'SELECT c.*, r.* FROM reservations r, resources c WHERE r.resource_id = c.id AND ' . $conditions;

Better would be:

return array(
'fields' => array('c.*', 'r.*'),
'tables' => array('reservations r', 'resources c'),
'conditions' => array('r.resource_id = c.id', $conditions)
);

So you can reuse it:

static public function withUsage() {
$query = self::query();
$query['fields'][] = '(SELECT COUNT(1) FROM foo WHERE id = r.id) AS usage';
return $query;
}

Voila. A query builder. With a few flaws, sure.