-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
[Model Fragments 5.0] Composing fragments with FactoryGuy#make/store#push
result in their properties being undefined
#366
Comments
Just an update, I checked and this issue is still present when using Ember Data 3.13.0 so it's more than likely specifically related to the Model Fragments refactor and not Ember Data. Looking at the commits between Ember Data 3.12.3 (which works with previous model fragments) and Ember 3.13.0 to my eye doesn't show anything that could make this happen emberjs/data@284c8c3...df469d4 |
So I've dug into this a little bit more and have been able to reproduce it without Factory Guy. It seems to be a consequence of using Take the following code which is something Factory Guy does internally.
let store = this.owner.lookup('service:store');
let manager = store.createFragment('person', {
nickName: 'The White Wolf',
title: 'Zoo Manager'
});
store.push({
'data': {
'type': 'zoo',
'attributes': {
manager
},
'id': 1
}
});
// Model Fragments < 5.0 + Ember Data 3.12
store.peekRecord('zoo', 1).manager.nickName //=> 'The White Wolf'
// Model Fragments 5.0 + Ember Data 3.13+
store.peekRecord('zoo', 1).manager.nickName //=> undefined So it looks like something changed where passing a fragment into Saying that, should this have ever worked? Was it just a "happy accident" that this worked before? I always believed So to round up I guess my questions are (specifically to @igorT)
Edit: I've updated my reproduction PR to remove Factory Guy and just use |
undefined
FactoryGuy#make/store#push
result in their properties being undefined
Closing as this was fixed in Factory Guy in adopted-ember-addons/ember-data-factory-guy#449 |
I'm opening this here but to be honest I'm not sure if the issue is in the Model Fragments
RecordData
refactor or the Ember Data upgrade (considering we need to upgrade to Ember Data 3.16).Background
The Factory Guy addon gives you a set of APIs to bootstrap your models in tests. The
make
helper allows you to push records directly into the store rather than need to use thepush
,pushPayload
orcreateRecord
APIs to bootstrap your models. A common pattern when usingmake
is to compose your test models with other models created usingmake
. For example take the followingperson
Ember Data model which contains a fragment:This can be created in a test by doing the following (once you've created your factories correctly). Here we create a user model and pass it an
info
fragment model.The problem
It appears passing a fragment to a model like above causes the properties of
info
to beundefined
rather than the values which were originally on the model.Strangely, if you pass a model to another model, or a fragment to another fragment it works correctly. It specifically seems to be the case where you pass a fragment to a model which isn't working. I've pushed a draft PR here which has a failing test (and some passing ones) to illustrate the problem.
Potential bug
The problem seems specifically to be an issue all the way down in
EmberObject
when we are pushing the_internalModel
property on the object to create the model instance. Looking at the screenshot below, the passed inprops
have the correct value, but once the model is created they are "lost" and come back asundefined
.And just to clarify, the failing test in the PR passes on the commit before the RecordData refactor.
/cc @igorT @richgt
The text was updated successfully, but these errors were encountered: