-
Notifications
You must be signed in to change notification settings - Fork 138
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
parse_strategy feature should allow richer matching with existing linked or embedded resources #85
Comments
Copy/Paste of Nick's response on roar-talk: the new option parse_strategy: :sync is pretty dumb: Instead of automatically creating new Address instances for the :addresses collection, it uses the instances and syncs their properties. Should we try to identify the strategies in a github issue? |
One valuable strategy could be where
|
Ignoring how the matching would work, I see those fundamental concepts for strategies:
collection :addresses, parse_strategy: [
sync_with: lambda {|doc| a = Address.find(doc[:id]) ? a : Address.new }] That could be abstracted with a dedicated strategy. Actually, now that I look at it, this works already if you use the |
That is encouraging! But what is the :instance option? I don't recognize it in the documentation. |
The |
I'll use representable's These 2 examples illustrate a POST or PUT to (UPDATE: What I wanna point out is: it's quite simple to implement the "model-syncing" in representable where representable will retrieve real object instances from the DB. However, we have to speak about different semantics when processing collections.) Adding/Replacing
Adding New
Skipping/Deleting
|
After editing the last comment 3 times I finally understood what we want! It's two different things. 1. Process Incoming Collection
Representable will parse this collection and sort out which item to retrieve from the DB (probably by checking the 2. Sync CollectionAfter the incoming collection is mapped to real objects, the user actually has to decide if he wants to add those objects, update the collection, update existing objects, only, etc. |
That looks pretty good! In the case of replacement, it would be nice to decide what to do with the replaced document. In some cases you might want to keep the resource available for others (e.g. removing a user from your twitter's "following" list) and in some cases you might want to delete the resource entirely (e.g. removing a tweet ... NSA notwithstanding). Perhaps a callback would work there? |
Hi guys, just interesting is it any progress on this? thanks for your work! |
Yeah, totally! This goes into |
@apotonick thanks for feedback i have json collections on client side i looking for some solution which allow me sync in simple way what you mean "goes into disposable"? |
Create and update already works with representable, only delete needs to be implemented. Are we talking about collections or singular properties here? Haha, |
Ok, some more explanations. Representable/Roar/Reform's job is transforming data to and from Ruby objects and not to create, find or delete ActiveRecord models. This belongs to another layer, which will be provided in |
Parse strategies got superseded by populators which are way more intuitive. http://trailblazer.to/gems/representable/3.0/populator.html |
that link doesnt work |
I know, still writing it! 😉 |
hurry up! :) |
@apotonick https://github.com/apotonick/roar#syncing-objects still cites |
I've got a model for People and Addresses. People have many addresses.
In my PersonRepresenter, I've got:
I initially stumbled upon the sync thing because I noticed that if I did a POST of a person, but didn't include the _embedded address array, it would delete my existing address collection for a given person.
Note, I'm doing some matching on POSTs. If you do a post of a person and the server finds that a matching person already exists then it passes the existing person object to the consume! call in the person controller.
Is there a way I can:
The text was updated successfully, but these errors were encountered: