I'm running into an issue of querying data against Ember data.
I have three models:
media
: which multiple models inherit from image
: which inherits from media
note
: which is a standard model.
I'm trying to get all of the note
s of an image
but the query I'm trying isn't working.
// imageModel.js
import Ember from 'ember';
import DS from 'ember-data';
import MediaModel from 'models/mediaModel';
export default MediaModel.extend({
fileName: DS.attr('string'),
fileExt: DS.attr('string'),
url: DS.attr('string'),
});
// mediaModel.js
import DS from 'ember-data';
export default DS.Model.extend({
notes: DS.hasMany('note', { inverse: 'noteable' }),
});
// noteModel.js
import DS from 'ember-data';
import Ember from 'ember';
export default DS.Model.extend({
category: DS.attr('string'),
text: DS.attr('string'),
image: DS.belongsTo('image'),
noteable: DS.belongsTo('media-model', { polymorphic: true }),
});
Once I have an image
, I do image.get('notes.length')
, but even if an image does have note
s associated with it, I'm always getting back 0
. Am I querying this the wrong way?
Does the fact that image
belongs to media
affect how I can query the hasMany
of media
?
Thank you
Aucun commentaire:
Enregistrer un commentaire