Currently BasePeer will add the join criteria,
table.column=table2.foreign_key_of_column, under the following conditions:
1. Criteria has been set up as
criteria.addSelectColumn(ProjectPeer.PROJECT_ID);
criteria.add( ProjectVisitorPeer.VISITOR_ID, visitor_id );
2. and the TableMap for project_visitor sets up a foreign key reference
between project_visitor.project_id and project.project_id
I do not know how this might work if the two TableMaps that are involved are
associated with a different DatabaseMap. I do not have experience
performing joins between tables in different databases, and from what I saw
in the generated SQL it would appear that the join is between tables in the
same database. Is there an SQL standard for cross database joins? Is this
something that is common in db servers?
BasePeer has been written so that multiple databases can be used in an
application, and it sounds like Jon has added some more code towards this,
but as I am unfamiliar with interactions between different databases,
BasePeer is not geared towards this activity.
However, if you want to write the join explicitly you need to do it
something like I showed:
> > selectCriteria.add("forcing a join", (Object)(ProjectPeer.PROJECT_ID +
"=" +
> > ProjectVisitorPeer.PROJECT_ID), Criteria.CUSTOM );
> >
Using
selectCriteria.add( ProjectPeer.PROJECT_ID, ProjectVisitorPeer.PROJECT_ID );
you are setting project.project_id equal to some string i.e.
project.project_id='A234'. So BasePeer is behaving correctly. Why can't
you use the CUSTOM add format. Oh, BTW, it will probably have to be written
like:
selectCriteria.add(ProjectVisitorPeer.PROJECT_ID,
(Object)(ProjectPeer.PROJECT_ID + "=" + ProjectVisitorPeer.PROJECT_ID),
Criteria.CUSTOM );
In order to use the same add method for both setting column='string_value'
and a join columnA=columnB, it would be necessary to check every column in
the database (or every column in every database?) whenever setting a column
equal to a String. I did not think that was acceptable. We might want to
add a addJoin method to Criteria, if the CUSTOM format is undesirable. Is
there some other way?
----- Original Message -----
From: jon * <[EMAIL PROTECTED]>
To: Turbine <[EMAIL PROTECTED]>
Sent: Tuesday, May 16, 2000 8:51 PM
Subject: Re: BasePeer problem
> on 5/16/2000 7:21 PM, John McNally <[EMAIL PROTECTED]> wrote:
>
> > I think this can be solved two ways. If you are selecting
> > ProjectPeer.PROJECT_ID, the join should be automatic, so I assume you
are
> > not selecting it. You can either add it to the select columns or try
>
> Actually, I am selecting that....there is a:
>
> criteria.addSelectColumn(ProjectPeer.PROJECT_ID);
>
> The problem is not with the join though...
>
> As I said before, the join is being made properly...the problem is the
> single '' around the right hand side of the join...please look at that SQL
I
> posted in my first message.
>
> > A bit ugly, but currently, this is the way to get any sql you want into
the
> > where clause.
>
> That won't work because the join IS being made properly...the problem is
the
> '' around it...for this kludge to work, I would have to remove the above
> criteria line and that would be bad.
>
> -jon
>
> --
> Java Servlet Based - Open Source | Collab.Net
> Bug/Issue Tracking System | now hiring smart people
> <http://scarab.tigris.org/> | <http://Collab.Net/jobs/>
>
>
>
> ------------------------------------------------------------
> To subscribe: [EMAIL PROTECTED]
> To unsubscribe: [EMAIL PROTECTED]
> Problems?: [EMAIL PROTECTED]
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Problems?: [EMAIL PROTECTED]