cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nishant Neeraj <nishant.has.a.quest...@gmail.com>
Subject querying vs using relationship list and iterate
Date Tue, 08 Jun 2010 14:41:39 GMT
Hi,

I have three tables USERS, MEMBERSHIPS, GROUPS -- where membership is a
linking table that joins users and groups in many-to-many relationship, and
also stores users' role in the group.

Sometime when I need to know whether a user exists in a group [or what role
a user has in a group], I can do it by two ways:

1. groups.getMembershipList() and iterate over the list inflating each
member and comparing with the User object that is on test. like

for(Membership m: g.getMembershipList())
{
   if(m.getUser().equals(testUser)
       return true;
}

Or.

2. I can just write a query using Expression.

Expression.forString(Membership.class, "user = $testUser and group=$group");


Can someone suggest which one is better approach? Or, is there a even better
third approach?

Thanks
Nishant

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message