Hi there,

On 19/11/2005, at 4:46 PM, Randy Becker wrote:

I'm coming up against some issues with modifying my database - whenever I modify an object, the change is reflected in the database, but is not displayed correctly until the current session is ended and a new one created. Am I doing something wrong when I change the DB?

I'm doing something like this:

EOEditingContext editingContext = session().defaultEditingContext();

EOEnterpriseObject newRequest = EOUtilities.createAndInsertInstance ( editingContext, "Request" ); Object itemPK = EOUtilities.primaryKeyForObject( editingContext, requestedItem).objectForKey("itemPK");

Why are you dealing with the primary/foreign keys in code?

Unless you really need to know about it you shouldn't deal with them at all. It's a database artefact that your application doesn't need to concern itself with. i.e., let EOF handle them transparently. In your EOModel make sure that these keys are _not_ class attributes.

newRequest.takeValueForKey( itemPK, "itemPK" );
newRequest.takeValueForKey( personPK, "personPK" );

Don't create relationships like that. You need to think in Objects and not database fields. EOF will translate your objects appropriately.

Person aPerson = EOUtilities.createAndInsertInstance(ec, "Person");
Item anItem = EOUtilities.createAndInsertInstance(ec, "Item");

Request aRequest = ( Request )EOUtilities.createAndInsertInstance ( ec, "Request" );
aRequest.addObjectToBothSidesOfRelationshipWithKey( anItem, "items" );
...
aRequest.addObjectToBothSidesOfRelationshipWithKey( thePerson, "person" );
aRequest.takeValueForKey( new NSTimestamp(), "dateRequested" );

ec.saveChanges();

"Dashboard" won't display the correct information until I end the session and create a new one.

If you update your _eoobjects_ correctly then you'll always see your changes consistently.

Have you been through the Apple tutorial for Web Applications?

with regards,
--

Lachlan Deck


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to