Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need to "reopenClass" to set the url for an ember-data model?

I found that if I try to include the url in the original definition of an ember-data model it blows up in my REST adapter but if I simply "reopenClass" it's fine.

What is the technical reason behind this? (below is the working example)

CodeCamp.Speaker = DS.Model.extend({
    id: DS.attr('number'),
    name: DS.attr('string'),
    session: DS.belongsTo('CodeCamp.Session')
});

CodeCamp.Speaker.reopenClass({
    url: 'sessions/%@/speakers'
});
like image 407
Toran Billups Avatar asked Oct 01 '12 19:10

Toran Billups


1 Answers

Calling extend on an object sets instance attributes, whereas reopenClass sets class attributes.

The url attribute is a class-level attribute,

Ember.get(CodeCamp.Speaker, 'url')

as opposed to:

speaker = CodeCamp.Speaker.createObject()
Ember.get(speaker, 'name')
like image 115
Bradley Priest Avatar answered Nov 03 '22 01:11

Bradley Priest