Reputation: 813
I am new to emberjs and I'm currently working on a new project. My application has 3 models namely Member, Project and Task.
For 1 and 2, everything is fine.
However, for the relationship between project and members, a member can either be a simple member of the project or a project manager.
In my database schema, I represented this relationship by having an additional table called project_members and had an additional field called 'role' which can either be 0 (meaning a simple member) or 1 (meaning a project manager).
What would be the best way to represent this using ember-data models? How should I represent the relationship and how and where should I include the additional 'role' field?
Thanks
Upvotes: 1
Views: 442
Reputation: 840
Not sure if it would work since I haven't tried having multiple attributes that point to one model but you could add these attribute in your project model like
projectManager: DS.belongsTo('member'),
members: DS.hasMany('member')
Then for the member model
projectManagerTo: DS.hasMany('project')
projects: DS.hasMany('project')
Or if you have anyway of knowing the project manager with just the member model data you can use a computed property.
projectManager: function() {
// some logic to determine which of the members is the project manager
}.property('members')
Upvotes: 0