-
-
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
Extract embedded belongsTo relationships in DS.EmbeddedRecordsMixin #1633
Conversation
This code previously handled embedded hasMany relationships, but not embedded belongsTo relationships. Note that this patch only implements extraction, and not serialization.
👍 this would be super useful, I was about to submit a similar PR myself |
@alexspeller @emk I have a fork of DS.EmbeddedRecordsMixin which was the result of adding support for belongsTo relationships and sat in a PR #1516 for about a couple months. See: https://github.com/pixelhandler/ember-data-extensions |
@pixelhandler: Oh, nice! For those who aren't familiar with DS.EmbeddedRecordsMixin, it actually handles multiply-embedded records quite well, except for those that use has_one in ActiveModel::Serializers. Once this piece is in place, everything appears to work nicely. If @pixelhandler has matching serialization code, then we might want to go ahead and use his version. But it's definitely worth fixing has_one/belongsTo—it's pretty easy to do, and this code seems to do pretty much everything you might want once this one issue is fixed. If anybody needs use cases, documentation, etc., please let me know. But I think this is worth fixing. |
@bradleypriest do you think that DS.EmbeddedRecordsMixin will continue to be enhanced in the activemodel-adapter package? |
@pixelhandler I'd like to get the DS.ActiveModelAdapter/Serializer and DS.EmbeddedRecordsMixin supporting everything that the default rails ActiveModelSerializer gem can output. |
I think Mongo stuff will probably stay in separate Serializer/Mixin's for the meantime if that's what you're asking 😉 |
@bradleypriest @emk @alexspeller I'm using mongoDB, so I embed objects using the (Rails) model, not always in an instance of ActiveModel::Serializer. Can someone tell me if ActiveModel:Serializers can do something like I've used I am not sure if DS.EmbeddedRecordsMixin is missing support for In my opinion if ActiveModel::Serializers allows something like I just tried out using This is the proposal I made for supporting belongsTo using has_one in a serializer: http://discuss.emberjs.com/t/extend-ds-activemodelserializer-support-for-embedded-objects-belongsto-relationship-using-has-one |
Yes, you can do Note that if you want this to work with Ember Data, you'll need to also use Here's how DS.EmbeddedRecordsMixin works:
The problem occurs in step (1): DS.EmbeddedRecordsMixin walks the entire embed hierarchy in one pass, which means it needs to know about both Anyway, with a patch like this, I think that DS.EmbeddedRecordsMixin will extract anything I've ever seen generated by ActiveModel::Serializers. And please feel free to use my unit test with somebody else's code, of course. Anyway, please let me know if I can help in any way here. Thank you for your consideration! |
@emk I updated pixelhandler/ember-data-extensions with your test and added the support for nested objects (belongsTo / has_one). @bradleypriest if you think support for |
Hi @pixelhandler, if it's handled by the AMS gem then yes, definitely. I'm just about to start adding integration tests here https://github.com/bradleypriest/ams_integration_app |
@bradleypriest I opened PR #1637 which is based on PR #1516. |
I just came across this issue in my app. It was returning |
Any idea of when can this be merged? :) Thanks! |
@bakura10 @bradleypriest said this on Twitter: https://twitter.com/bradleypriest/status/453438310254272512 |
Thanks, that's good to hear :). |
We merged #1637 so closing this |
DS.EmbeddedRecordsMixin handles embedded hasMany relationships, but not embedded belongsTo relationships. This patch attempts implements nested belongsTo extraction, with full unit tests, but not the corresponding serialization primitives.
Use case: I'm dealing with a project that has an array of values, each of which contains an embedded array, each value in which contains another embedded belongsTo value, which in turns contains another embedded array. DS.EmbeddedRecordsMixin almost handles this, but it breaks on the embedded belongsTo value.
It would be nice to implement the corresponding serialization support, for the sake of completeness, but I don't know whether anybody would use it.
Please let me know if I can improve this patch in any way. Thank you for all your work on Ember Data!