Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 847
blueFast Avatar asked Jul 09 '26 02:07

blueFast


2 Answers

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

like image 95
Finn MacCool Avatar answered Jul 11 '26 17:07

Finn MacCool


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);
like image 40
user2243570 Avatar answered Jul 11 '26 18:07

user2243570



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!