In my application users have many meals. meals belong to a user. I have it so that a user can currently post a meal by creating a record and saving it. Immediately after completing this my console threw the error:
Error: Assertion Failed: You need to pass a model name to the store's modelFor method at new Error (native)
I then wrote my model hook for getting meals, when I started to get the error:
TypeError: Cannot read property 'some' of undefined
I am not certain what is causing this. Here is my code:
User Model:
import DS from 'ember-data';
import { hasMany } from 'ember-data/relationships';
export default DS.Model.extend({
email: DS.attr('string'),
height: DS.attr('number'),
weight: DS.attr('number'),
age: DS.attr('number'),
tdee: DS.attr('number'),
gender: DS.attr('string'),
activity_level: DS.attr('number'),
meals: hasMany('meal')
});
Meal model:
import DS from 'ember-data';
import { belongsTo, hasMany } from 'ember-data/relationships';
export default DS.Model.extend({
meal_type: DS.attr('string'),
created_at: DS.attr('date'),
user: belongsTo('user'),
// meal_items: hasMany('meal_item')
});
Meal route:
import Ember from 'ember';
export default Ember.Route.extend({
model() {
return this.get('store').findAll('meal');
},
actions: {
createMeal(data) {
let meal = this.get('store').createRecord('meal', data);
meal.save();
}
}
});
I am new to ember, but have a hunch it may be related to explicit inverses? An advice is appreciated. I can post more code if something needs clarification.
Aucun commentaire:
Enregistrer un commentaire