-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data wont render solution #212
Comments
^ See solution above. |
So I created the model, and it still throws the error that the model doesnt exist. This is my profile model:
And this is my favorite model:
The error is: I've tried playing around with the pluralizations: making a model for "favorites", saying profile has many "favorite" singular. Am I just messing up the pluralizations or am I linking these relationships incorrectly? |
Trying to follow this guid as directed from older closed solutions but what exactly are the inverses> https://guides.emberjs.com/v2.5.0/models/relationships/ When I follow the guide, I get an errror that say it cant find my inverses |
If favorites is a join table, you may need to have profile_id: DS.belongsTo('profile', { Also, check to make sure in your API you have those Inversei set in your favorites model. Let me know if his changes anything. |
Then through this favorites join, you should be able to call profiles from recipes and the other way around without having to reference the join table. |
^I did that last night and got: So i made a "favorites" (plural) model and got the same error. I tried every combination of singular in my profile model, and even when I make both of them "favorite" (singular) it still says "favorites undefined" in the plural. I have the inverses labeled in my backend as:
and
|
For serializing relationships out of the backend, you'll want to look at You don't want to use export default DS.Model.extend({
given_name: DS.attr('string'),
- user_id: DS.belongsTo('user'),
+ user: DS.belongsTo('user'),
level: DS.attr('number'),
favorites: DS.hasMany('favorites'),
// schedules: DS.hasMany('schedule'),
}); export default DS.Model.extend({
- profile_id: DS.belongsTo('profile'),
+ profile: DS.belongsTo('profile'),
- recipe_id: DS.belongsTo('recipe')
+ recipe_id: DS.belongsTo('recipe'),
}); |
SOLUTION: I got favorites to work and this solution is going to walk through how to do it for a similar join table that I have called "schedules" which also joins a profile to a recipe. Moral of the issue: Ember works like an angel if you give it what it wants from the backend, and you run into a bit of trouble if you give it more than it wants. (Hence the importance of the pluck(:id) BACKEND: PROFILE MODEL:
Schedules Model:
Recipes Model:
Profile Serializer:
Schedule Serializer:
Recipe Serializer:
FRONT END: Schedule Model:
[the routes for schedule are the normal findAll for plural and findRecord for singular] Profile Model:
Recipe Model:
|
Page would not render data for profile.
Routes were set up correctly but this was the model:
Errors Thrown:
Solution Part 1:
You can't insert into a model a property DS.hasMany if that property does not yet have a model defined somewhere in your ember client.
Solution Part 2;
DS.attr('number')
Not integer.
The text was updated successfully, but these errors were encountered: