Can I define a default value for ember-data model attributes?

pjmorse picture pjmorse · Jun 4, 2012 · Viewed 11.3k times · Source

When I define an attribute for a model in ember-data, can I specify a default value?

The ember-data model definition suggests attributes are defined like this:

attributeName: DS.attr('number')

...with an optional second argument as an options hash. I've looked at the code but my code-reading skills aren't up to figuring out what attributes I can put in the options hash. Is it possible to do something like this?

attributeName: DS.attr('number', { default: 0 })

or

attributeName: DS.attr('boolean', { default: false })

?

Answer

pangratz picture pangratz · Jun 4, 2012

You were close, it's defaultValue, see attributes.js#L63-65.