Re: How do I update a relationship in a WODisplayGroup?
Re: How do I update a relationship in a WODisplayGroup?
- Subject: Re: How do I update a relationship in a WODisplayGroup?
- From: Zak Burke <email@hidden>
- Date: Tue, 13 Dec 2005 16:45:44 -0500
email@hidden wrote on 12/13/05 3:57 PM:
I can change any of the attributes
[snip]
However, while I can change [a relationship]
and I even verify it is stored in the database,
my WODisplayGroup still shows the old value.
In my experience, WO will update attributes persisted to the DB, but for
relations it only pulls from its cache. Even when you call
setRefreshesRefetchedObjects(true) on a fetch spec, related objects are
still pulled from the cache instead of from the DB. You may be
encountering something different by throwing display groups into the
mix, but the behaviour seems to be similar.
To guarantee fresh relations, I either call
setPrefetchingRelationshipKeyPaths(NSArray relation-names) on the
fetch-spec or I call a relationship-loading method (code below) on the
list I get back from the fetch.
HTH --
zak.
public static void preloadRelationship(NSArray sourceEOs, String
relationshipName)
{
if (sourceEOs == null || sourceEOs.count() == 0)
return;
EOEnterpriseObject sampleEO = (EOEnterpriseObject)
sourceEOs.objectAtIndex(0);
EOEditingContext ec = sampleEO.editingContext();
EOObjectStoreCoordinator osc = (EOObjectStoreCoordinator)
ec.rootObjectStore();
osc.lock();
try
{
EOEntity entity =
EOModelGroup.modelGroupForObjectStoreCoordinator(osc).entityNamed(sampleEO.entityName());
EODatabaseContext databaseContext =
EODatabaseContext.registeredDatabaseContextForModel(entity.model(), osc);
EORelationship relationship = entity.relationshipNamed(relationshipName);
databaseContext.batchFetchRelationship(relationship, sourceEOs, ec);
}
finally
{
osc.unlock();
}
}
_______________________________________________
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