1

I'm having some trouble modeling these relationships and getting the correct data in my app. I have users, links, and bookmarks. Where bookmarks is a join table so users can have many bookmarks, and links can have many bookmarks

<!-- user -->
export default DS.Model.extend({
  username: DS.attr('string'),
  bookmarks: DS.hasMany('bookmark', { async: true }),
});

<!-- link -->
export default DS.Model.extend({
  title: DS.attr('string'),
  url: DS.attr('string'),
  bookmarks: DS.hasMany('bookmark', { async: true }),
});

<!-- bookmark -->
export default DS.Model.extend({
  link: DS.belongsTo('link', { async:true }),
  user: DS.belongsTo('user', { async:true })
});

In firebase this is what my data looks like:

user
  - userkey
    - bookmarks
      - bookmarkkey : true

link
  - linkkey
    - bookmarks
      - bookmarkkey : true

bookmark
  - bookmarkkey
    - link : linkkey
    - user : userkey

In ember, when I pull a user model I'm able to access the related bookmarks, but not the link that is related to the bookmarks.

How can I fix this?

EDIT 1 this is how I'm attempting to access bookmarks and links:

store.findRecord('user', userId).then((user) => {
  this.set('bookmarks', user.get('bookmarks'));
})

And then in the template something like this:

{{#each bookmarks as |bookmark|}}
  <div>
    {{bookmark.link.title}}
  </div>
{{/each}}
kaustubhb
  • 399
  • 1
  • 5
  • 19
  • How are you trying to access the `bookmarks` and `links`? – Mikko Paderes Sep 05 '16 at 14:41
  • just added an edit to explain how I'm accessing bookmarks and links. Even when I console log `bookmarks`, under relationships, I see the link `id`, but the internal object is empty. No `link` attributes. – kaustubhb Sep 05 '16 at 20:07
  • Hmm. That seems to be about right. Are you sure it's not a firebase security rules issue that's causing this? Also, have you tried to just fetch the link from a bookmark without going through the user? – Mikko Paderes Sep 06 '16 at 08:35

0 Answers0