-
Notifications
You must be signed in to change notification settings - Fork 26
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
Support embedded relations (embed: always-style) #24
Support embedded relations (embed: always-style) #24
Conversation
Will have to create a serializer to be able to test this properly.
It is green already, yahoo! Need to set up a negative test also I think.
… is arguably more complex).
(No Travis set up for the repo? 😛) |
Ah, now I see that the Travis stuff is coming up. Nice! |
@perlun Thank you for the hard work. I will do my best to investigate this as soon as possible. Could you explain beforehand what there is to gain with |
Sure. The point is when building the app, retrieving data perhaps via the DS.RESTAdapter or similar, sometimes it makes a lot of sense to "retrieve all data at once". Suppose for example you have an order. You might want to retrieve (and return) not just the order, but also the order lines, and maybe other data as well. Of course, you can retrieve it all using asynchronous relations (the default pattern w/ Ember Data), but from our experience (building quite a lot of enterprise apps using Ember), the "embed always" style of data is sometimes a lot easier to work with, making implementation of the app less cumbersome. You have all data accessible at once, and there is no need for the |
Hmm. You did read about caching in order to reduce the number of requests to one? Then all data is in memory, making your app a lot faster. Regarding the |
@frederikbosch - just to make things clear. Our use case is not limited to using the localforage-adapter. It is a mix of an offline and an online store, with some requests going to the online store, others going to offline (and some going first to offline with online afterwards. :) ) So we can't really optimize for "localforage only" scenarios but need to think very carefully on how to build a data model that works well for both REST and localforage scenarios. In our experience, In any way, the Simply put: In our app(s), it makes sense to design the data model like this. |
Support embedded relations (embed: always-style)
@perlun Thanks for your hard work, much appreciated! I have merged your code and tagged a new version. |
Cool @frederikbosch, thanks for that! |
Hey @perlun, would it be possible for you to provide an example of how you were able to combine both the REST adapter and the localforage adapter for your objects? Do you just set the adapter for the top-level model to |
@srsgores You could have a look at Ember Sync. Because Ember Sync was in alpha stage when I started this adapter, I use the |
@srsgores I also just noticed Ember Fryctoria. It was created by a contributor of this adapter. |
@srsgores - apart from the suggestions by Frederik, here's how I did it:
(we don't use I then use a |
@perlun, ingenious. Thanks for describing your process. I will update this with any hurdles I come across in my own implementation. I think we should consider adding some of these "hybrid" adapter approaches to the readme, at least until ember 2.0 comes out. What do you guys think? |
@perlun, where does the |
You create a custom store using something like:
It could also be that you can make it work by just giving the serializer the right name, and Ember will find it automagically. But the problem then is that it will be used for both the offfline and online stores. (if you need more help, I can send you our hourly rates.... 😉) |
Hi,
As promised in #22, here is a PR that adds support for
embedded: 'always'
style data.I have also added the accompanying tests, and an example of how to set up the serializer for these cases.
Questions/suggestions? Let me know. All tests are green of course, and I will start using this in our own app now (since everything seems to work correctly).
Without this PR, the adapters causes errors since it tries to load data for relations where the child data is already available, which is obviously a problem.