On 6/13/07, John Siracusa <[EMAIL PROTECTED]> wrote:
> On 6/13/07, Adrian Howard <[EMAIL PROTECTED]> wrote:
> > I can't see how to get_routes that have a relation ship to both a
> > location with a name of 'London' and another with a name of 'Brighton'.
>
> Off the top of my head, this seems like you'd need two "EXISTS (...)"
> subqueries to do this.  To use subqueries in a Manager call, you
> currently have to specify them as hard-coded SQL, either using the
> "clauses" parameter or by passing scalar refs in the query parameter.

Could you not just join the locations table twice?

my $routes = Route::Manager->get_routes(
    query => [
        't2.type' => 'start',
        't2.name' => 'London',
        't3.type' => 'end',
        't3.name' => 'Brighton',
    ],
    with_objects => ['locations', 'locations'],
);

I did a quick test and it appears to work.  It generates the following SQL:

SELECT
  t1.id,
  t1.name,
  t2.id,
  t2.name,
  t2.route_id,
  t2.type,
  t3.id,
  t3.name,
  t3.route_id,
  t3.type
FROM
  routes t1,
  locations t2,
  locations t3
WHERE
  t2.name = ? AND
  t2.type = ? AND
  t3.name = ? AND
  t3.type = ? AND
  t1.id = t2.route_id AND
  t1.id = t3.route_id
ORDER BY t1.id

I am not sure if the resulting 'route' objects will have their
'locations' relationships populated fully though, so this may still
have some issues...  But it should at least get you the correct
routes.

Cheers,

Cees Hek

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to