• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Qualifier to match on content of two to-many relationships
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Qualifier to match on content of two to-many relationships


  • Subject: Re: Qualifier to match on content of two to-many relationships
  • From: Aaron Rosenzweig <email@hidden>
  • Date: Thu, 12 May 2016 23:28:48 -0400

Hi Paul and everyone,

What you did is ok - not bad but since you are asking for more here you go.

It is probably a bad idea to model the back relationship from “Role -> Users” as one role could be used by thousands of users. You don’t want to fault all those people in when you “addToBothSidesOfRelationshipWithKey().” That said you *could* model it and be careful to not add to both sides and be careful never to trip that fault. You could also model it as a “non class” invisible property. If you had this relationship you could do the following.

EOQualifier noticeQualifierForUser = Notice.ROLES.dot(Role.USERS).containsAnyObjectSatisfying(loggedInUser.identityQualifier())

You can use that one qualifier to fetch all the Notices for your user. 

The “identityQualifier()” could be defined in your EO like so:

public EOQualifier identityQualifier() {
final EOEntity entity = entity();
final NSDictionary<String, Object> primaryKeyDictionary = primaryKeyDictionary(false /* inTransaction */);
final EOQualifier thatAreThis = entity.qualifierForPrimaryKey(primaryKeyDictionary);
return thatAreThis;
}

Note: “containsAnyObjectSatisfying()” is a thin wrapper of “ERXExistsQualifier.” If you prefer, you could create that exists qualifier directly and specify if you want an “in” or exists syntax to be generated. 

Aaron Rosenzweig / Chat 'n Bike
e:  email@hidden  t:  (301) 956-2319
Chat 'n Bike Chat 'n Bike

On May 10, 2016, at 6:22 PM, Paul Hoadley <email@hidden> wrote:

Hello,

I have two entities, User and Notice, each of which has a to-many relationship to Role called roles. The business rule here works as follows. Say Notice.roles contains two Roles, R1 and R2. If User.roles contains either R1 or R2, then the Notice is applicable to that User—that is, Notice.roles says that for each Role, the Notice applies to any User that has that Role.

I have a static method on Notice to return an NSArray<Notice> applicable to some supplied User. (There are other matching criteria, but this is the part I want to try and simplify.) At the moment, I’m doing this:

NSMutableArray<EOQualifier> roleQuals = new NSMutableArray<EOQualifier>();
for (Role r : user.roles()) {
roleQuals.add(Notice.ROLES.containsObject(r));
}
EOQualifier roleQual = ERXQ.or(roleQuals);

While this works, it seems awkward. Is there a way to create this qualifier (which is essentially looking for any match between User.roles and Notice.roles) in one step?


-- 
Paul Hoadley
http://logicsquad.net/


Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Qualifier to match on content of two to-many relationships
      • From: Samuel Pelletier <email@hidden>
References: 
 >Qualifier to match on content of two to-many relationships (From: Paul Hoadley <email@hidden>)

  • Prev by Date: Re: Qualifier to match on content of two to-many relationships
  • Next by Date: Re: Closure of WOCommunity Association
  • Previous by thread: Re: Qualifier to match on content of two to-many relationships
  • Next by thread: Re: Qualifier to match on content of two to-many relationships
  • Index(es):
    • Date
    • Thread