The newOrder() and newOrderItem() are just convenience methods I wrote
for creating and inserting into the editing context to test this
particular EOF scenario. Then I used the removeFromItems() method
generated by the Wonder templates. But I believe that ends up calling
removeObjectFromBothSidesOfRelationshipWithKey().
Anyways, I tested with and without calling processRecentChanges()
between the add and remove. And that made the difference!
On Oct 27, 2009, at 8:46 PM, Ricardo J. Parada wrote:
Very interesting... You are right David. I have confirmed the same
too.
Adding a call to ec.processRecentChanges() between the add and the
remove makes this work as I expected it.
Here's the code:
EOEditingContext ec = ERXEC.newEditingContext();
Order order = Order.newOrder(ec);
OrderItem anItem = OrderItem.newOrderItem(ec, 1, "iMac 27\" Quad-
Core 2.66GHz/1TB/4GB", "1999.00");
order.addToItemsRelationship(anItem);
order.computeTotalAmount();
ec.processRecentChanges(); // <--- It seems like a BUG this is
needed for the remove below to work!!
order.removeFromItems(anItem);
ec.saveChanges();
On Oct 27, 2009, at 8:15 PM, David LeBer wrote:
On 2009-10-27, at 7:52 PM, Chuck Hill wrote:
On Oct 27, 2009, at 4:40 PM, Lon Varscsak wrote:
Try:
Create an Order and OrderItem and insert both into an editing
context.
Then add the item to the order using
order.addObjectToBothSidesOfRelationshipWithKey(item, "items").
Then call editingContext.processRecentChanges()
Then removeObjectFromBothSidesOfRelationshipWithKey(item,
"items") to remove the item.
Then save the editing context.
Here is the docs on that method:
Forces this EOEditingContext to process pending insertions,
deletions, and updates. Normally, when objects are changed, the
processing of the changes is deferred until the end of the
current event. At that point, an EOEditingContext moves objects
to the inserted, updated, and deleted lists, delete propagation
is performed, undos are registered, and
ObjectsChangedInStoreNotification and
ObjectsChangedInEditingContextNotification are posted. You can
use this method to explicitly force changes to be processed. An
EOEditingContext automatically invokes this method on itself
before performing certain operations such as saveChanges. This
method does nothing in Java Client applications.
I'm struggling with how to describe why that works. :P
It should not work. processRecentChanges() is called during
saveChanges() so it should not affect the item getting deleted.
My feeling is that it not getting deleted after initial insertion
is a bug.
I can confirm that calling ec.processRecentChanges() in between the
addObject... and removeObject... calls does work. Though I don't
know why at this point.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/rparada
%40mac.com
This email sent to rpar...@mac.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com