Skip to content
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

Async in prod and debug version does not perform the same #4428

Closed
cbou opened this issue Jun 13, 2016 · 9 comments
Closed

Async in prod and debug version does not perform the same #4428

cbou opened this issue Jun 13, 2016 · 9 comments

Comments

@cbou
Copy link

cbou commented Jun 13, 2016

Because of the use of assert in the debug version of EmberJS Data, when using relationship with async: false the records needs to be loaded before using the relationship.

In the prod version, the assert is not present which is allow to the relationship even if the related record is not loaded yet. It will be updated as soon as the record is loaded.

To me the assert should be changed into a warn.

https://github.com/emberjs/data/blob/master/addon/-private/system/relationships/state/belongs-to.js#L143
https://github.com/emberjs/data/blob/master/addon/-private/system/relationships/state/has-many.js#L207

@fivetanley
Copy link
Member

Hi Charles,

Is it just that it's confusing that it's an error in development but allowed in production? Maybe we should change it to always throw?

@cbou
Copy link
Author

cbou commented Jun 13, 2016

No please don't do this!

It's actually quite useful because sometimes the related record is loaded after.

@pangratz
Copy link
Member

It's actually quite useful because sometimes the related record is loaded after.

@cbou I would say if you explicitly mark a relationship as synchronous via { async: false } but sometimes the record is loaded after, you should treat your relationship as asynchronous. Otherwise side effects cannot be ruled out and this might result in unexpected behavior.

Any reason you're not using asynchronous relationships here?

@cbou
Copy link
Author

cbou commented Aug 17, 2016

I used { async: false } to prevent EmberJS loading some models.

The reason is that I have some models which are loaded and updated outside of EmberJS. I keep them sync using store.pushPayload. I still defined these mixed models inside EmberJS in order to use them there (read only) and they are linked to other models which are loaded and updated in EmberJS.

@pangratz
Copy link
Member

I used { async: false } to prevent EmberJS loading some models.

Relationships are only loaded if they are explicitly requested... Maybe there is some code in your application which triggers loading of relationships as a side effect.

Can you provide some sample code / ember-twiddle demonstrating your use case?

@cbou
Copy link
Author

cbou commented Aug 17, 2016

I request them in the templates when calling {{a.b.name}} and if the relationship is not loaded, I don't want EmberJS to load it. I want to have an empty name first until it's pushed from the other part of the app.

@pangratz
Copy link
Member

Hmm, I don't know of any easy solution to that at the moment 😔

References added in #3303 allow you to check the loading state of relationships without triggering a fetch, but they are currently not available in templates...

@cbou
Copy link
Author

cbou commented Aug 17, 2016

For the moment it's fine as long as an error is not throw in production like @fivetanley suggested.

It would be better if assert could be changed in warn but it's a nice to have.

@runspired
Copy link
Contributor

Closing this as a duplicate of #5226

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants