entity var may be needed to cache the EOEntity and prevent constantly searching through the models :-/ The other problem I see is that entity() may result in null when there's no ec and the entity is not in the default model group. Not sure how often that happens.
I'm thinking this method should look something like to prevent the NPE:
public Object handleQueryWithUnboundKey(String key) {
// Handles primary key attribute values
if(entity().primaryKeyAttributeNames().contains(key)) {
// Deleted object. Return null.
if(editingContext() == null) {
return null;
}
NSDictionary pkDict = EOUtilities.primaryKeyForObject(editingContext(), this);
// New object. Return null.
if(pkDict == null) {
return null;
}
// Return value for key
return pkDict.objectForKey(key);
}
return super.handleQueryWithUnboundKey(key);
}
Alternately, is this something that we could simply remove and put into an eogen template for anyone who needs this? The more I look at this the less I like it. This method is going to get called a ton for any ERD2W app that uses object.someKey in rules.
In my ERUsers framework I have
55 : (pageConfiguration = 'CreateERUser' and propertyKey = 'clearPassword' and object.password.length > 0) => componentName = "R2D2WPropertyMessage" [com.webobjects.directtoweb.Assignment]
Which means the current method is called and creating a pkDict for every single property level component on every single page that isn't an ERUser. I just tested it on a ListMovie page. On a ten item page, handleQueryWithUnboundKey is called 960 times.