Need help modeling relationships


#1

Currently we have models for a user, app and page.

app.js

export default DS.Model.extend({
  title: attr(),
  pages: hasMany('page')
});

user.js

export default DS.Model.extend({
  fullName: attr(),
  // What relationship would go here?
});

page.js

export default DS.Model.extend({
  title: attr(),
  app: belongsTo('app')
});

We are trying to make an interface that shows all available apps and pages for a user. Each user can subscribe to different pages. We would like to see what pages the user is subscribed to, and what app the page is related to. In the interface we want to be able to use check boxes to make different page subscriptions for each user.

Here is an example that shows all available apps and pages.

  • App 1
  • page 1
  • page 2
  • page 3
  • App 2
  • page 1
  • page 2
  • page 3

We would like to be able to see only the apps and pages that a user is subscribed to. For example if a user is subscribed to App 1: pages 1 and 2, App 2: page 3. How can we show the entire list of apps with only the subscribed apps checked.

What would be a good way to model this using ember data?

This is what it would like for a user subscribed to some pages.

We would like to also be able to show a list of only the things a user is subscribed to.

Any help would be appreciated!


#2

How about adding a subscription model?

user.js

export default DS.Model.extend({
  fullName: attr(),
  subscriptions: hasMany('subscription')
});

subscription.js

export default DS.Model.extend({
  page: belongsTo('page'),
  user: belongsTo('user')
});

#3

Thank you! We used something very similar and that seemed to work!