• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: WOToOneRelationship and "dirty" editing context
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: WOToOneRelationship and "dirty" editing context


  • Subject: Re: WOToOneRelationship and "dirty" editing context
  • From: email@hidden
  • Date: Fri, 6 Jan 2006 12:04:15 -0500

Hi Chuck,

Hi Kevin,

On Jan 5, 2006, at 1:00 PM, email@hidden wrote:
On 05 Jan, 2006, at 02:12 PM, Lachlan Deck wrote:
On 06/01/2006, at 4:16 AM, email@hidden wrote:

My problem is that when I merely display the validatedUser and do not make any changes, I am still seeing the object as being updated by logging the updatedObjects() of the editing context. If I remove the WOToOneRelationship from the page, and replace with a simple WOTextField, I do not see the object as being updated , when I do not perform any changes to the user. This is the behavior I would like to see, and would expect, when using WOToOneRelationship.

Try updating your User like...

public void setDepartment( Department aDepartment ) {
	Department currentDepartment;

	currentDepartment = department();
	if ( currentDepartment != aDepartment ) {
		...
	}
}

That way your entity will not "update" itself when you're simply
giving it the same value.

While this may work to avoid updating the entity itself, it will

	1) break our existing auditing scheme that relies on monitoring
the editing context's updatedObjects NSArray.


Allow me to strongly caution you away from relying on the contents of the updatedObjects array for an audit trail. It is not what you think it is, you are heading for problems. An object appearing in that array only means that willChange() has been called on that object. It does not mean that it has actually changed. A better name for that list might be possiblyUpdatedObjects() or objectToCheckForChangesWhenSaving().

Code like this:
client.setName(client().name())
will also result in the object being added to the updated list.

The definitive way is to filter the objects in that array with the
condition:

object.changesFromSnapshot(object.editingContext
().committedSnapshotForObject(object)).count() > 0

Or you can use a boolean method on your EOs to check this:

public boolean hasBeenUpdated() {
    return editingContext().updatedObjects().containsObject(this) &&
	(changesFromSnapshot(editingContext().committedSnapshotForObject
(this)).count() > 0);
}


Thanks for this information!! I spoke with the development team that wrote our auditing logic and this seemed to solve some of their problems of having records audited that were not truly changed. This tip (and some others that came in) are helping to redesign a new approach by using the snapshots and subclassing our EOs.



2) require us to manually update nearly all of our entities in our
application (well over 200 that will have to one relationships)
with customized code.

If you are using EOGenerator (and with too entities you ought to
be!), then this update is trivial.


Yes, we are using EOGenerator and agree it is very easy to use and will now be easy to implement our new strategy.


Chuck



Based on this information, I did some more testing by turning on the EOAdaptorDebugEnabled=true to see the SQL and if an update was actually being sent to the database. [Not that I did not believe it :-) ] When the WOToOneRelationship popup was not changed, nothing was updated in the database (good), even though the updatedObjects array (or possiblyUpdatedObjects array as Chuck put it) showed my object. So, I am relieved.

Is this just something that the WOToOneRelationship will always cause and I should not worry about it? It seems as if the WOToOneRelationship must be doing something like the client.setName (client().name()) to display the relationship value. Maybe other interface components that deal relationships will also put the object in the updatedObjects array by their very nature, but EOF will be smart enough (through the snapshot) to figure out if an update is truly warranted.


Thanks again for everyone's help,

Kev
_______________________________________________
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


  • Prev by Date: Re: EOModel error
  • Next by Date: JDBC and MySQL 5.0
  • Previous by thread: Re: WOToOneRelationship and "dirty" editing context
  • Next by thread: fun eomodeler error
  • Index(es):
    • Date
    • Thread