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}}