mongoid-history
mongoid-history copied to clipboard
WIP: track changes on embedded_one
- [x] embeds_one with changes in Parent
- [x] embeds_one with empty changes in Parent
- [ ] embeds_many with empty changes on Parent
Coverage increased (+0.004%) to 99.752% when pulling f741e5c7c9d395d3c589d491be70a1ac2cf1314b on mateuspontes:master into 439c0e107a00dd8ba32c38448ff2e6593566bc39 on mongoid:master.
Coverage increased (+0.004%) to 99.752% when pulling f741e5c7c9d395d3c589d491be70a1ac2cf1314b on mateuspontes:master into 439c0e107a00dd8ba32c38448ff2e6593566bc39 on mongoid:master.
Coverage increased (+0.004%) to 99.752% when pulling f741e5c7c9d395d3c589d491be70a1ac2cf1314b on mateuspontes:master into 439c0e107a00dd8ba32c38448ff2e6593566bc39 on mongoid:master.
Great progress. If you solve 2/3 of the cases that's already good enough to merge, so feel free to do that if the last one turns out to be too hard.
Also, there's nothing wrong with taking a dependency on something like https://github.com/bopm/mongoid_relations_dirty_tracking, in fact I would prefer that since it (theoretically) specializes in one thing better.
I'm actually doing this now using https://github.com/bopm/mongoid_relations_dirty_tracking
@johnnyshields so I can pause this POC and wait your PR.
@johnnyshields pls tell me if I can help you with code or something like that.
Hi folks,
Thanks for the work on this. What's the current status? What combination of extensions/code do I need to make #187 work?
@mpetazzoni I'm facing the same problem. I'm using bopm/mongoid_relations_dirty_tracking to track modifications but it post all embeds_many to history_track and after that my embeds_many data are duplicated (see this commit). Without this gem I cann't track changes in embed.
I was trying to create a POC to track changes in embeds_one, but I think the best option is to use MRDT. Waiting @johnnyshields update this issue
@mateuspontes no PR needed, this works for me now:
class Customer
include Mongoid::History::Trackable
include Mongoid::RelationsDirtyTracking
embeds_many :phones
relations_dirty_tracking only: [:phones]
track_history on: [{ phones: %i(tag number extension) }]
end
@mateuspontes sorry I didn't read this carefully enough, if this PR is specifically for the embeds_one
case then please go ahead, my apologies I didn't realize there was an issue there.
@johnnyshields thx for your help, your code works for me but I end up with my embeds duplicated, I'm using mongo 3.4
Something like that:
{
"customer": {
"name": "Doe",
"phones": [
{
"comercial": "11111"
}
]
}
}
After update @customer:
{
"customer": {
"name": "Doe",
"phones": [
{
"comercial": "11111"
},
{
"comercial": "11111"
}
]
}
}
@mateuspontes that sounds like an issue unrelated to this gem. When you are updating make sure you are using the _id
field on the embedded objects.
@johnnyshields I'm using rails 4.2.7 and mongoid 5.2, the issue is related to bopm/mongoid_relations_dirty_tracking, without mongoid_relations_dirty_tracking I cann't store relations changes.
IMHO mongoid-history should track embeds changes as it can track has_many, actually it doesn't track embeds, the code isn't work and it is confirmed as a bug.
After update parent (with mongoid_relations_dirty) action.update(action_params)
.
Without mongoid_relations_dirty I cann't see embeds diff, mongoid-history doesn't track it. That was the motivation to PR.
> db.actions.findOne({"_id": ObjectId("5903a7f07ce04a617e3c3bf1")})
{
"_id" : ObjectId("5903a7f07ce04a617e3c3bf1"),
"name" : "Parent Action",
"operations" : [
{
"_id" : ObjectId("5903ae5c7ce04a63e0d8149f"),
"name" : "Duplicated child"
},
{
"_id" : ObjectId("5903ae5c7ce04a63e0d8149f"),
"name" : "Duplicated child"
}
],
"version" : 2
}
Still looking forward for a mergeable PR here!