Search code examples
namespacesember.jsember-data

Reserved attribute names in Ember.js models


I have a Post model with the following fields:

BlogApp.Post = DS.Model.extend({
    author: DS.attr('string'),
    title: DS.attr('string'),
    preamble: DS.attr('string'),
    content: DS.attr('string'),
    created: DS.attr('date'),
    comments: DS.hasMany('BlogApp.Comment'),
    lastUpdate: DS.attr('date')
});

After rendering, instead of the Post.content, the result is like:

<BlogApp.Post:ember272:1>

Other fields rendering are OK. I guess content is conflicting with some internal property. I have a few questions:

  1. is there any workaround when the REST API has names that conflict with Ember internals?
  2. is there other forbidden attribute names I should be aware?

[update]

The name clash is with the controller, not with the model. It is not a definitive list but watch out for other common database column names like:

  • model
  • transaction
  • is_new
  • is_deleted
  • store
  • errors

I guess Ember developers not as afraid of namespace-related bugs as this poor pythonist.

BTW, Angular.js guys got it right: they always prefix API attributes and methods with $ effectively preventing this kind of bug.


Solution

  • I'm trying to answer your two questions:

    1 you can define a mapping for all of you Keys, here an example for the content property

    App.Adapter.map('App.Post', {
      myContent: {key: 'content'}
    });
    

    2 as far I know there is no such explicit list of reserved names in ember, but as a rule of thumb very generic names like content should be avoided (preventively)

    Hope it helps