blueFast
blueFast

Reputation: 44351

Reusing a model for different objects

I have defined the following model:

App.Node = DS.Model.extend({
    type: DS.attr('string'),
    name: DS.attr('string')
});

The data for this model can be retrieved via REST in api/nodes.

Now I have similar data which can be found in api/phonenumbers. The structure of the data is the same, so I wanted to reuse the model. I have defined:

App.Phonenumber = App.Node;

But this is not working. The request is still being sent to api/nodes for this model. Why? How can I reuse models?

Upvotes: 3

Views: 210

Answers (2)

user2243570
user2243570

Reputation: 163

Can you ask 'Is Phonenumber a Node?' In your context?

If yes, than extension is your solution.

If not, then you probably can ask 'Does a Phonenumber resemble a Node?'.

In that case, I would do the following:

var genericNameConfig = {
  type : DS.attr('string'),
  name : DS.attr('string')
};

App.Node        = DS.Model.extend(genericNameConfig);
App.Phonenumber = DS.Model.extend(genericNameConfig);

Upvotes: 2

Finn MacCool
Finn MacCool

Reputation: 808

i think App.Phonenumber = App.Node.extend({}); might do the trick.

Upvotes: 4

Related Questions