Skip to content

Instantly share code, notes, and snippets.

@jphpsf
Created April 25, 2011 01:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jphpsf/940046 to your computer and use it in GitHub Desktop.
Save jphpsf/940046 to your computer and use it in GitHub Desktop.
storeKeyExists_example.js
// Does it already exists?
if (MyApp.MyModel.storeKeyExists('foobar')) {
// The key exists, so retrieve the record to update it
var record = MyApp.store.find(MyApp.MyModel, 'foobar');
// We only need to update the sources
record.set('something', 'yeah');
} else {
// Otherwise create a new record
var record = MyApp.store.createRecord(MyApp.MyModel, {
'id': 'foobar',
'something': 'yeah'
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment