Open skinnerdev opened 8 years ago
Thanks a lot for this, looks solid to me. Will review it ASAP.
Cheers,
On Thursday, 10 March 2016, David Skinner notifications@github.com wrote:
I saw issue #26 https://github.com/beauby/jsonapi-datastore/issues/26 and realized we had this logic on a fork of this project. Here is the code we've implemented to provide this functionality.
I've added a property to data store models that holds information about other models that reference it. This property is used during delete to assist with the complete removal of this object from the store. Any time a model with references is added to the store, we touch the references and "inform" them that they have been referenced.
The delete process uses the data in the associations array to find other objects in the store that reference the model to be deleted. If the deleted model is referenced with a hasMany relationship, the model to be deleted is removed from the referencing model's relationship array. If the reference is a hasOne/belongsTo relationship, the referencing model's relationship is
given a new blank datastore model with only the _type property set.
You can view, comment on, or merge this pull request online at:
https://github.com/beauby/jsonapi-datastore/pull/28 Commit Summary
- Added a property to datastore models that holds information about other models that reference it. This property is used during delete to assist with the complete removal of this object from the store.
File Changes
- M src/jsonapi-datastore.js https://github.com/beauby/jsonapi-datastore/pull/28/files#diff-0 (23)
Patch Links:
- https://github.com/beauby/jsonapi-datastore/pull/28.patch
- https://github.com/beauby/jsonapi-datastore/pull/28.diff
— Reply to this email directly or view it on GitHub https://github.com/beauby/jsonapi-datastore/pull/28.
Lucas Hosseini lucas.hosseini@gmail.com
Awesome, this feature is clearly a must! A few minor remarks, but I'd love to merge that ASAP.
I've pushed up the changes as per our conversation thus far. On the property name issue, I think _dependents is fairly descriptive. Though if someone has a better idea for a name I'd be happy to change it.
Great, thanks! _dependents
seems good to me. Last thing needed would be one or two tests. I could probably write some tomorrow if you don't have time.
The original work I had done on this is on another computer with my testing environment set up. I don't have a testing setup on this machine. If I have some time next time I am by it, I'll try and write some. Though might be a few days... :\
No worries, I can do it. Note that running the tests should just be a matter of
$ npm install
$ gulp test
Thanks for the reminder! I had some extra time and setup the tests on this machine. I went and added a test and discovered a few tweaks that would help keep it clean. Let me know if there are any adjustments needed. :)
Nice, I think we're really close now, a tiny bit of cleanup and we should be good to merge!
Added the _addDependence and _removeDependence.
Awesome, will review ASAP!
Hey @skinnerdev – any news on this front?
I saw issue #26 and realized we had this logic on a fork of this project. Here is the code we've implemented to provide this functionality.
I've added a property to data store models that holds information about other models that reference it. This property is used during delete to assist with the complete removal of this object from the store. Any time a model with references is added to the store, we touch the references and "inform" them that they have been referenced.
The delete process uses the data in the associations array to find other objects in the store that reference the model to be deleted. If the deleted model is referenced with a hasMany relationship, the model to be deleted is removed from the referencing model's relationship array. If the reference is a hasOne/belongsTo relationship, the referencing model's relationship is given a new blank datastore model with only the _type property set.