-
-
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
Issue setting belongsTo with PromiseProxy #3172
Comments
@raytiley Do you know if it used to work on previous versions ? |
I'm pretty sure it worked before. The problem is definitely inconsistent and weird. My access of the PromiseProxy is from a service. I have a computed property on a service like such // services/location.js
activeLocation: Ember.computed('locationId', {
get: function() {
this.get('store').find('show', this.get('locationId'));
}
}) Then in a route's model hook I do: model: function() {
return this.get('store').createRecord('show', {
location: this.get('location.activeLocation') // comes from the locations service above
}
} If the code is just like above I don't get the error. But calling So I tried adding a beforeModel: function() {
return this.get('location.activeLocation');
},
model: function() {
return this.get('store').createRecord('show', {
location: this.get('location.activeLocation') // comes from the locations service above
}
} The above code throws the error in my first message. What's doubly weird is that I do a To get things working I can access beforeModel: function() {
return this.get('location.activeLocation');
},
model: function() {
return this.get('store').createRecord('show', {
location: this.get('location.activeLocation.content') // comes from the locations service above
}
} The above code throws no errors, and the Hope this helps. |
Quickly looking at the code, it seems like return this.get('store').createRecord('show', {
location: this.get('location.activeLocation') // comes from the locations service above
} should work, at least there is a mechanism to accept setting a belongsTo with a PromiseProxy if it already has the content. It would be great if you could find which one here is undefined. Also I noticed in your example: // services/location.js
activeLocation: Ember.computed('locationId', {
get: function() {
this.get('store').find('show', this.get('locationId')); // the model name seems weird for a location
}
}) Maybe just a typo here, but if not, it could be the cause of the problem |
Yeah.. the model name in the service is a typo. In the stack the |
I have absolutely no idea how that could happen. I think newRecord is an InternalModel instance, and it should definitely have a type... It would be great if you could file a failing test |
Can you point me in the direction of a similar test I can try to tweak? I'm super short on time for the next few weeks, and I typically suck at ED tests. I could also do a quick screenhero session with someone if they want to poke around the stack trace live. @igorT knows where to find me :) |
@raytiley I will try to make a test now, since the base scenario looks easy to reproduce (at least I think) |
@sly7-7 ❤️ I'm good for now, like I said I worked around it by accessing the Thanks again. |
So, maybe the test is a little contrived, but it reproduces your case: test("A record can be created with an async belongsTo already in store", function() {
expect(1);
var Group = DS.Model.extend({
people: DS.hasMany()
});
var Person = DS.Model.extend({
group: DS.belongsTo({ async: true })
});
env.registry.register('model:group', Group);
env.registry.register('model:person', Person);
var group;
run(function() {
group = store.push('group', { id: 1 });
});
var groupPromise = store.find('group', 1);
groupPromise.then(async(function(group){
var person = env.store.createRecord('person', {
group: groupPromise
});
equal(person.get('group.content'), groupPromise);
}));
}); |
So it turns out that your code and this code is trying to put a real record (from the promiseProxy's content property) while I think the relationship now expects an internal model. |
nice catch, I thought i handled that in the internalModel refactor, let me double check |
@sly7-7 yes the record promise should call getRecord on the promise content. Weird that the tests pass, maybe they just assert the id, as there is a test for this case. Should be an easy fix |
@igorT could you give me a pointer to this test ? also is it worth it to add the above test? |
https://github.com/emberjs/data/blob/master/packages/ember-data/tests/integration/relationships/one-to-one-test.js#L165 is an example. Confused why it passes. |
@raytiley If you could try with the PR, it would be great :) |
I have simple code like this:
This is giving me an exception:
I'm currently on
1.0.0-beta.19+canary.34efef04a2
The text was updated successfully, but these errors were encountered: