0

Ember data's DS.Store has a filter function that calls adapter.shouldSave(record) (github). In the case of using Ember data's RESTAdapter, the RESTAdapter's shouldSave function is called.

shouldSave returns !reference.parent (github) where reference seems to be just like the record from the debugging I've done. But I couldn't find the parent of the reference I was working with.

Question 1: Does anyone know what return !reference.parent means here for the RESTAdapter?


Question 2: What does the Ember.K mean in the generic Ember data Adapter's shouldSave (see github)?

4

1 回答 1

1

Question 1: Does anyone know what return !reference.parent means here for the RESTAdapter?

After reading trough the source the line return !reference.parent basically means that reference is the record that is being currently handled and parent would point to it's parent in the case the record is a child of a parent model having hasMany / belongsTo relationships.

Example:

App.Post = DS.Model.extend({
  comments: DS.hasMany('App.Comment')
});

App.Comment = DS.Model.extend({
  post: DS.belongsTo('App.Post')
});

In the example a record of type App.Comment has as it's parent App.Post. So this line makes perfect sense return !reference.parent which would return false is the reference does not have a parent a thus not being part of any relationship.

Question 2: What does the Ember.K mean in the generic Ember data Adapter's shouldSave (see github)?

Ember.K simply is a function returning this. See here for reference.

Hope it helps.

于 2013-07-05T23:40:27.487 回答