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 protected]  t:  (301) 956-2319             
        

On May 10, 2016, at 6:22 PM, Paul Hoadley <[email protected]> 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 protected])
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/aaron%40chatnbike.com
> 
> This email sent to [email protected]

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to