• 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: To-Many Qualifiers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: To-Many Qualifiers


  • Subject: Re: To-Many Qualifiers
  • From: Aaron Rosenzweig <email@hidden>
  • Date: Tue, 15 Apr 2014 12:30:11 -0400

Hello Kevin,

I’ll take a swing at a new qualifier for you.

Verbally:
A profile sometimes points directly to the account I want. Other times, the primary account for a profile is NOT the one I want but it has teams which vicariously point back to the account I want. Give me all those profiles.

Style notes (entirely optional):
Try to avoid starting with “ERXQ.anything” such as “ERXQ.or()” and “ERXQ.keypath()” Technically it is ok but it’s harder to rest and disrupts the visual flow of the code. 

Don’t use “_KEY” - It’s easier to just call “.key()” when you need it as you’ll soon see.

Code sniff:
Anytime you have a to-many relationship involved, consider an “exists” qualifier.

Utility method:
You need a way to “qualify yourself.” Your primary keys are probably hidden (rightly so). You don’t want to qualify on “name”, “title”, “description" or anything else since you already have the Account object you want in hand. So put this utility method either in your “Account” EO or preferably in your abstract parent class if you have one (between “Account” and “ERXGenericRecord”):

public EOQualifier identityQualifier() {
EOEntity entity = ERXEOAccessUtilities.entityNamed(editingContext(), entityName());
EOQualifier qualifier = entity.qualifierForPrimaryKey(primaryKeyDictionary(false /*inTransaction*/));
return qualifier;
}

The new code:

// Generates a qualifier for the Profile for this account and the Profiles of any account on the same team (or that is the intention)
public static EOQualifier visibleToAccountQualifier(Account account)
{
EOQualifier accountIsDirectlyTheOneIWantQualifier = account.identityQualifier();
EOQualifier accountHasTeamForTheOneIWantQualifier = new ERXExistsQualifier (
account.identityQualifier() /*subQualifier*/,
Account.TEAMS.dot(Team.ACCOUNTS).key() /*baseKeyPath*/,
);
EOQualifier finalAccountQualifier = new ERXOrQualifier(
accountIsDirectlyTheOneIWantQualifier,
accountHasTeamForTheOneIWantQualifier);

EOQualifier profileQualifier = new ERXExistsQualifier (
finalAccountQualifier /*subQualifier*/,
Profile.ACCOUNT.key() /*baseKeyPath*/, /*Note: this is a to-one relationship, but that’s ok*/
);
return profileQualifier;
}    


Wrap-up:

Note: be sure to either update Wonder or at least “cherry pick" the latest version of the ExistsQualifier.

Kevin give this a try and report back. It’s funny how the ExistsQualifier can solve 90% of the complex data-mining queries we could encounter. This is especially true for “to-many” relationships. 

You can “flip” the “exists” sql into an “in” with an additional boolean parameter. Play with the true-false value of “useInClauseInstead” to tune performance. If you want to learn more then watch the slides here:
http://www.chatnbike.com/presentation_existsQualifier/

You’ll be able to lick this, don’t worry. Dig in :-)

Cheers,
Aaron Rosenzweig / Chat 'n Bike
e:  email@hidden  t:  (301) 956-2319
Chat 'n Bike Chat 'n Bike
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: To-Many Qualifiers
      • From: Kevin Hinkson <email@hidden>
References: 
 >To-Many Qualifiers (From: Kevin Hinkson <email@hidden>)

  • Prev by Date: Re: Apache adaptor error with http header
  • Next by Date: Re: Apache adaptor error with http header
  • Previous by thread: To-Many Qualifiers
  • Next by thread: Re: To-Many Qualifiers
  • Index(es):
    • Date
    • Thread