-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[BUGFIX] normalize model name for belongs to relationships #5477
[BUGFIX] normalize model name for belongs to relationships #5477
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! And great catch :) We'll be moving the singularize
to a different point soon to address #5475 , but that's immaterial to here.
@agrobbin if you have time to add tests, I can help you locate the right spot and draft them :) |
@runspired absolutely, just point me in the right direction and I'll add them! |
@runspired were you able to locate where tests should go for this change? |
@agrobbin haven't looked yet, sorry. I should get back to you this afternoon though :) |
Unless @runspired has a better suggestion I think it would be ok to add a test for this change to tests/unit/model/relationships-test.js. |
1cb1b5a
to
7e32805
Compare
@bmac @runspired I just pushed up test coverage for this. Let me know if everything looks good! |
const StreamItem = DS.Model.extend(); | ||
|
||
let User = DS.Model.extend({ | ||
streamItems: DS.hasMany(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should actually assert, as there is no inverse, surprised it does not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why it didn't assert, but I added the inverse relationship to StreamItem
above.
const UserProfile = DS.Model.extend(); | ||
|
||
let User = DS.Model.extend({ | ||
userProfile: DS.belongsTo(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment as below, this should assert and I'm surprised it does not, UserProfile needs the inverse defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto here, I added the inverse relationship definition to UserProfile
above.
7e32805
to
64461e5
Compare
const relationships = get(User, 'relationships'); | ||
const relationship = relationships.get('stream-item')[0]; | ||
|
||
assert.equal(relationship.meta.name, 'streamItems'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
give asserts a meaningful description as the last arg (same for the other test).
User = store.modelFor('user'); | ||
|
||
const relationships = get(User, 'relationships'); | ||
const relationship = relationships.get('stream-item')[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we likely want an assertion that we did in fact normalize to stream-item
from streamItems
here, instead of just relying on it implicitly being tested due to how we access. Same with the test above.
@agrobbin saw you resolved a few comments, left a few more. Resolve those and we should be good :) |
Given these models: ```ruby const User = DS.Model.extend({ userProfile: DS.belongsTo(), streamItems: DS.hasMany() }); const UserProfile = DS.Model.extend({ user: DS.belongsTo() }); const StreamItem = DS.Model.extend({ user: DS.belongsTo() }); ``` The inferred model type of `User.streamItems` will be `stream-item` while the type of `User.userProfile` will be `userProfile`. This goes against the concept of all model types being dasherized. With this change, `User.userProfile` will be converted into `user-profile`.
64461e5
to
ff47a3e
Compare
@runspired just pushed some more updates! |
Thanks for all of the help @runspired and @bmac! Looking forward to seeing this included in the next Ember Data release. |
) Given these models: ```ruby const User = DS.Model.extend({ userProfile: DS.belongsTo(), streamItems: DS.hasMany() }); const UserProfile = DS.Model.extend({ user: DS.belongsTo() }); const StreamItem = DS.Model.extend({ user: DS.belongsTo() }); ``` The inferred model type of `User.streamItems` will be `stream-item` while the type of `User.userProfile` will be `userProfile`. This goes against the concept of all model types being dasherized. With this change, `User.userProfile` will be converted into `user-profile`.
Given these models:
The inferred model type of
User.streamItems
will bestream-item
while the type ofUser.userProfile
will beuserProfile
.This goes against the concept of all model types being dasherized.
With this change,
User.userProfile
will be converted intouser-profile
.I'm not exactly sure where this kind of thing should be tested. It seems like it belongs in same place that the
hasMany
model type normalization tests reside, but I'm having trouble finding that place!