On Dec 9, 2003, at 1:05 PM, James Treleaven wrote:
> Might I ask how one searches on PK and FK values? (I cannot specify
> these columns in expressions I pass to SelectQuery(), can I?)
>
> I expect the answer is 'Use Raw SQL' - but I am far from expert when
> it comes to Cayenne.
Not necessarily. For PK search you can use this QueryUtils method:
http://objectstyle.org/cayenne/api/cayenne/org/objectstyle/cayenne/
access/util/
QueryUtils.html#selectObjectForId(org.objectstyle.cayenne.ObjectId)
And there is a whole class of expressions based on DbEntities that can
help with FK search (see ExpressionFactory.matchDbExp(..) for
instance). I know this is not discussed often here, because of our
general policy of "no meaningless keys in objects", but it is doable.
E.g. the QueryUtils method mentioned above uses this approach:
public static SelectQuery selectObjectForId(ObjectId oid) {
return new SelectQuery(
oid.getObjClass(),
ExpressionFactory.matchAllDbExp(oid.getIdSnapshot(),
Expression.EQUAL_TO));
}
Andrus
This archive was generated by hypermail 2.0.0 : Tue Dec 09 2003 - 13:19:45 EST