My DB model is as following:
A.id (1 : n) B.ad_id
So in cayenne for object A a
I can do a.getBArray()
which returns me all the entries from B from this given A entry. Yet I would like to filter on this list, based on the property active = 1
.
Obviously I can use Expression.fromString("active = 1")
with SelectQuery
, but for this approach I can't find how I associate the A instance under which I want to run this query on.
A different approach is to retrieve all entries from a.getBArray()
and filter in code searching only those that have active == true
, this approach is IMHO inefficient.
Recommendations are mostly appreciated.
Thank you, Maxim.
-- EDIT:
My current solution to is (object names have been replaced with a & b respectively):
long aId = DataObjectUtils.longPKForObject(db_a_instance);
String bSQL = "select * from b where active = 1 and a_id = " + aId;
SQLTemplate bQuery = new SQLTemplate(B.class, bSQL);
List<B> dbBs = context.performQuery(bQuery);
and I'm asking if there is a better, more elegent solution?
Thanks.