Created
May 28, 2014 21:31
-
-
Save sandalsoft/3783bbf907586b1d42b0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** from the ember-data b7 source for push(): | |
Push some data for a given type into the store. | |
This method expects normalized data: | |
* The ID is a key named `id` (an ID is mandatory) | |
* The names of attributes are the ones you used in | |
your model's `DS.attr`s. | |
* Your relationships must be: | |
* represented as IDs or Arrays of IDs | |
* represented as model instances | |
* represented as URLs, under the `links` key | |
For this model: | |
```js | |
App.Person = DS.Model.extend({ | |
firstName: DS.attr(), | |
lastName: DS.attr(), | |
children: DS.hasMany('person') | |
}); | |
``` | |
To represent the children as IDs: | |
```js | |
{ | |
id: 1, | |
firstName: "Tom", | |
lastName: "Dale", | |
children: [1, 2, 3] | |
} | |
``` | |
To represent the children relationship as a URL: | |
```js | |
{ | |
id: 1, | |
firstName: "Tom", | |
lastName: "Dale", | |
links: { | |
children: "/people/1/children" | |
} | |
} | |
``` | |
If you're streaming data or implementing an adapter, | |
make sure that you have converted the incoming data | |
into this form. | |
This method can be used both to push in brand new | |
records, as well as to update existing records. | |
@method push | |
@param {String or subclass of DS.Model} type | |
@param {Object} data | |
@returns {DS.Model} the record that was created or | |
updated. | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment