I’m using:
DEBUG: -------------------------------
DEBUG: Ember : 1.3.1
DEBUG: Ember Data : 1.0.0-beta.6
DEBUG: Handlebars : 1.3.0
DEBUG: jQuery : 2.0.2
DEBUG: -------------------------------
I have the following Ember Data model:
App.User = DS.Model.extend({
name: DS.attr("string"),
thisShouldBeFalse: DS.attr("boolean", {defaultValue: false}),
thisShouldBeTrue: DS.attr("boolean", {defaultValue: true})
})
When manually creating a model instance, and leaving thisShouldBeTrue
unspecified, then thisShouldBeTrue
has the value true
. This is expected.
model = this.store.createRecord("user", {
id: "12356",
name: "Foo Bar"
});
model.get("thisShouldBeTrue") //evaluates to true. This is expected
When instead querying the store/RESTAdapter
for a model instance, and the remote server’s REST API endpoint leaves thisShouldBeTrue
unspecified, then thisShouldBeTrue
has the value false
. This is unexpected.
model = this.store.find("user", "12356");
//an XHR to the API endpoint takes place... then later...
model.get("thisShouldBeTrue"); //evaluates to false. This is unexpected
Is this a bug in Ember Data’s defaultValue
logic in conjunction with RESTAdapter
?
P.S.: I’d like to provide a JSFiddle/JS Bin example that utilizes RESTAdapter
, but I couldn’t find a public JSON API endpoint that follows Ember Data’s naming conventions out-of-the-box.