I've been doing a lot of partially building queries and then passing them around for the application to add to before executing. This has been seriously useful and I think is a major benefit of using query object. Unfortunately it appears to be breaking DataMapper. Take the following example:
Code:
$job = new Job();
$job->where_in('jobs.id',$idArray)->include_related('location','name');
$person = new Person();
$person->where_in('persons.id',$idArrayTwo)->include_related('address','post_code');
$job->get(); // This time I don't want to alter the query (keeping it simple)
// Results in something like:
SELECT
jobs.*,
location.name AS location_name,
addresses.post_code as address_post_code // SECOND QUERY
FROM
jobs
LEFT OUTER JOIN locations ON jobs.location_id = locations.id
LEFT OUTER JOIN addresses ON persons.address_id = addresses.id // SECOND QUERY
WHERE
jobs.id IN(1,2,3)
AND persons.id IN(1,2,3) // SECOND QUERY
So it looks like only a single query object instance is used for all models and therefore you have to build your query and execute it before building another?
(N.B. notice in sql above that persons table isn't included in the query - guessing because the query builder thinks we already have our primary table in jobs).