On Dec 20, 2007, at 6:06 AM, Mike Schrag wrote:
> It works with Velocity, because I use those templates ... The define
> should be named "EOGenericRecord" and the value should be
> "er.extensions.ERXGenericRecord". You need to set this in
> each .eogen file.
Stop! Don't do it like that!
Instead, make a class (it can be empty for now) that extends
ERXGenericRecord. We'll call it JPMGenericRecord.
class JPMGenericRecord extends ERXGenericRecord {}
Then set EOGenericRecord to JPMGenericRecord.
Now you can add stuff you need across all your EO's to
JPMGenericRecord.
You'll thank me later. :-)
Here's some code to motivate you. It adds countRelationship() to
your to-manys so you can get a count of how many there are of
something with fetching them all:
public EOQualifier qualifierForRelationshipWithKey(String aKey)
{
this.willRead();
if ((aKey != null))
{
String anEntityName = this.entityName();
EOEntity anEntity =
EOModelGroup.defaultGroup().entityNamed(anEntityName);
EORelationship aRelationship = anEntity.relationshipNamed(aKey);
if (aRelationship != null)
{
EOEditingContext anEditingContext = this.editingContext();
EOGlobalID aGlobalID = anEditingContext.globalIDForObject(this);
String aModelName = anEntity.model().name();
EODatabaseContext aDatabaseContext =
EOUtilities.databaseContextForModelNamed(anEditingContext,
aModelName);
aDatabaseContext.lock();
NSDictionary aRow = aDatabaseContext.snapshotForGlobalID(aGlobalID);
aDatabaseContext.unlock();
EOQualifier aQualifier = aRelationship.qualifierWithSourceRow(aRow);
return aQualifier;
}
}
return null;
}
/**
* Return count for the given relationship.
*/
public Number countForRelationship(String key)
{
EOQualifier qual = qualifierForRelationshipWithKey(this, key);
if (qual != null)
{
return
ERXEOControlUtilities.objectCountWithQualifier(this.editingContext(),
this.entityName(), qual);
}
return null;
}
And this for your templates:
public Number count${relationship.capitalizedName}() {
return countForRelationship("${relationship.name}");
}
This archive was generated by hypermail 2.0.0 : Thu Dec 20 2007 - 11:29:26 EST