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

Avoid suggesting using data directly #35

Open
makepanic opened this issue Sep 6, 2015 · 2 comments
Open

Avoid suggesting using data directly #35

makepanic opened this issue Sep 6, 2015 · 2 comments

Comments

@makepanic
Copy link
Contributor

I don't know if this is something that should be mentioned in the readme but data is private api and shouldn't be used.

I got stung by it after using the data links directly in my templates for using a media link that is rendered in an image, i.e. {{my-image src=obj.nested.data.links.media}}.

The problem is that the data, which is an readonly alias for its internal model _data is converted by ember to an ember object with __ember_meta__, setters, getters and much more. That means the internal model is now an ember object (which is pretty bad).

This breaks pushing an already loaded record to the store (i.e. by ember after an store.find) because it tries to merge the stored record with the new incoming record. This happens without calling Ember.set which causes the ember added setter to throw an error because it needs to be invoked with Ember.set

20150818-130854

I solved this for myself by adding a links attribute links: attr() to all my models and reading the links values from that attribute. ({{my-image src=obj.nested.links.media}}).

This could be redundant if emberjs/data#2905 is fixed (emberjs/data#3419)

@rwjblue
Copy link

rwjblue commented Nov 3, 2015

I noticed this yesterday during an upgrade. I am unsure what the approved public API would be to grab links from the underlying internal model, but we should figure out a path forward if we can...

@maletor
Copy link

maletor commented Aug 16, 2016

I'm unsure of the path forward here as well. What does JSONAPIAdapter do with the links made available?

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

3 participants