Hi Travis,
Try something like this:
final Expression expression = Expression.fromString("name = $name and
owner.name = $name");
Map parameters = new HashMap(1);
parameters.put("name", "Fred");
SelectQuery query = new SelectQuery(Pet.class,
expression.expWithParameters(parameters));
List pets = dataContext.performQuery(query);
I seem to recall that if you want to use 'like', that it doesn't handle
the $name substitutions very well (I'm sure Andrus will yell at me if I
am wrong). If you need to use 'like', try this:
String name = "Fred";
Expression expression = Expression.fromString("name likeIgnoreCase '%" +
name + "%' and owner.name likeIgnoreCase '%" + name + "%'");
SelectQuery query = new SelectQuery(Pet.class, expression);
List pets = dataContext.performQuery(query);
-----Original Message-----
From: Travis Cripps [mailto:travi..pparentmotion.com]
Sent: Thursday, December 09, 2004 7:31 PM
To: cayenne-use..bjectstyle.org
Subject: Is it possible to compare entity keys in an object query?
Hi. I've been working with Cayenne for about a week. So far, I've
found it to be pretty nice.
After looking through the documentation and trying to experiment in
CayenneModeler, I've been unable to create a query that will compare a
key from one entity with a value from a related entity by traversing
the relationship.
Here's a simple example:
Imagine my simple model is:
Person (Entity)
pk id
name
Pet (Entity)
pk id
fk owner_id
name
owner (to-one relationship with person)
What I'd like to do is build a query like:
Query Name: PetHasSameNameAsOwnerQuery
Query Root: Pet
Qualifier: name caseInsensitiveLike owner.name
Is this possible in Cayenne? How would I represent that either in
CayenneModeler or in an Expression? I'd really appreciate the help.
Thank you very much!
Travis
This archive was generated by hypermail 2.0.0 : Fri Dec 10 2004 - 09:37:38 EST