baum icon indicating copy to clipboard operation
baum copied to clipboard

Updating node updated_at causes unwanted side-effects

Open imade-nl opened this issue 9 years ago • 3 comments

When I want to touch the timestamp of a nested Model it looses it's depth.

I have a nested Page model that has a relationship with a Content model. When I update the Content model I want to touch the updated_at timestamp of the Page model. This all works fine with protected $touches = ['page']; in the Content model, but as a bonus I get a set of extra queries that also set the depth off the Page model to zero.

-
UPDATE `contents` set `fields` = '{\"leader\":[{\"file\":\"2\",\"description\":\"\"}],\"about_titel\":\"\",\"about_tekst_1\":\"\",\"about_tekst_2\":\"\",\"contact_titel\":\"\",\"contact_tekst\":\"\"}', `updated_at` = '2016-09-29 23:52:45' WHERE `id` = '129'
UPDATE `pages` set `updated_at` = '2016-09-29 23:52:45' WHERE `pages`.`id` = '118'
SELECT * FROM `pages` WHERE `pages`.`id` = '118' LIMIT 1
SELECT * FROM `pages` WHERE `pages`.`id` = '118' LIMIT 1
SELECT max(`rgt`) as aggregate FROM `pages`
SELECT * FROM `pages` WHERE `pages`.`id` = '118' LIMIT 1
UPDATE `pages` set `depth` = '0', `updated_at` = '2016-09-29 23:52:45' WHERE `id` = '118' ORDER BY `pages`.`lft` ASC
1.060 m

Is there some kind of event that triggers these last 5 queries?

imade-nl avatar Sep 29 '16 22:09 imade-nl

Sorry for the late reply.

I've had a quick look at this, and I think it's caused by the saved event being caught in Baum\Node, which calls moveToNewParent then setDepth. It's obviously a bug, as we shouldn't be updating anything 'node-related' just because a time stamp changes.

I'll need to look in this more and implement a fix.

gazsp avatar Feb 08 '17 22:02 gazsp

Thanks for your response!
I hope you find a solution, it would make cache-busting a lot easyer. :-)

imade-nl avatar Feb 09 '17 12:02 imade-nl

I ran across this issue, too, and for anyone else needing a fix, I changed the default $moveToNewParentId from null to false and it seemed to solve it for me. This is line 67 in src/Baum/Node.php.

beneberle avatar Jan 02 '19 17:01 beneberle