1
votes

When a new record is created using Ember Data, then get("isDirty") returns true. But as yet, the user has made no changes to the record, and we can discard it without losing any of the user's work.

Is there any official, supported way to detect this situation, where a record has been created but no properties have been set?

(There's in incomplete answer to this question for a much older version of Ember Data, before it was substantially overhauled. The didSetProperty function still exists in current releases, but it's undocumented. Still, it might be a possible path to a solution if nothing official can be found.)

1

1 Answers

0
votes

Internally, the changed properties are tracked by the _attributes property. You could do a check of

record.get('isNew') && Ember.keys(record._attributes).length === 0

to see that it has just been created and nothing has been changed on it.

Note that this is not meant to be part of the external API, but I'm not aware of any external API to accomplish this.