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:
You’ll be able to lick this, don’t worry. Dig in :-)
Cheers,
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