-
-
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
belongsTo retrieved via "links" attribute cannot be accessed via get() #1443
Comments
I have just run into this issue too. Is this a known change in the API for ember-data 1.0? I haven't seen it mentioned anywhere in the docs. In my case I wasn't using a "links" hash but an array of IDs. |
In Ember Data 1.0, user.get('membership').then(function(membership) {
// use membership here
}); You can return a promise directly from the App.MembershipRoute = Ember.Route.extend({
model: function() {
return this.modelFor('user').get('membership');
}
}); |
@wycats That is not the issue. The issue is that when the promise resolves, it is not providing the model, but rather that it's providing a construct with requires me to call |
Are you saying that in here: |
@wycats In this use case, I think the promise was resolved, so as a user when using a belongsTo, even with async I would like to be able to use user.get('membership') returns the corresponding model. @abobwhite Did I correctly understood your expectation ? |
This is actually extremely critical to how the whole thing works: When you make a relationship async, it will always, 100% of the time return a promise when you get it. Otherwise, code could randomly change between returning a promise and a value based on other, non-local code. That would be disastrous. A lot of promise-related annoyances will become easier with ES6: spawn(function*() {
var memberships = yield this.get('memberships');
// memberships is the value that would have been passed to .then
}); |
Also, for what it's worth, I'm considering making all relationships async, because the current way it works has proven to be somewhat confusing and prone to people hacking at options until they get the behavior they want. |
@abobwhite in +1 on making it always async. It will be a little annoying for the always embedded case, it is too subtle and leads to other complexity that I think is harder to deal with. |
@wycats @kselden Even when in some controller logic if I would like to just use @sly7-7 Yes, you understood me correctly. |
@wycats This seems to be causing issues with computed properties too, for example in 0.13 I was using this code: showAttachments: (->
(@get('viewingSelf') || @get('isFriend')) && @get('user.attachments.length')
).property('user.attachments.@each', 'viewingSelf', 'isFriend') Which no longer works because |
I am having the same problem. Even after the record is fully loaded, now that my relationship is async, it becomes a PromiseObject instead of a model instance. I want to be able to call model methods on that object. Am I missing something? At what point does a PromiseObject turn into a materialized model? update
Is this the best way to do this? |
For posterity, whatever happened to "async as default" as discussed above? |
@toobulkeh relationships are |
If I have a model "User" which has a relationship:
membership: DS.belongsTo('membership', {async : true})
that is fetched from the links hash in the payload from the server, that membership is correctly fetched and loaded on to the User. That being said, sayinguser.get('membership')
does not return the membership model. Instead,user.get('membership').get('content')
is required to actually use the model...this seems like a bug to me. Am I missing something?The text was updated successfully, but these errors were encountered: