Random Joe
Random Joe

Reputation: 640

Multiple relationship between two objects

How do I define multiple relationships between two objects in Ember? For example A user can be either a staff or a customer the differentiator is the userType property. If a customer buys a product, the product object need to have link to the customer that bought it and the staff that facilitated the sale.

Upvotes: 0

Views: 132

Answers (1)

Oren Hizkiya
Oren Hizkiya

Reputation: 4434

Here is a basic version of a data model that would suffice for what you have described. You can adapt it for your needs. I have used the app global haven't specified whether you are using ember-cli.

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

App.Order = DS.Model.extend({
    orderedBy: DS.belongsTo('user'),
    facilitatedBy: DS.belongsTo('user')
});

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

A useful tool for creating a first pass of a data model when you are unsure of the ember syntax is Ember Data Model Maker. You can use it to see how you should set up your model definitions and then modify them later.

Upvotes: 1

Related Questions