You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is currently an issue on rails 4.2 and mysql where children of a has_one relationship are having their UUID updated at the same time as the parent. The strange thing is that a mysql UPDATE query is run overwriting the exact same data.
To replicate the issue I have created a dummy app with a failing test suite. In the example we have Owner has_one Dog which does not use activeuuid and displays the rails default behaviour. We also have User has_one Car which does use uuid.
If we first take Owner has_one Dog we can confirm that the Dog record is never touched when updating the Owner.
o = Owner.create
(0.1ms) BEGIN
SQL (0.2ms) INSERT INTO `owners` (`created_at`, `updated_at`) VALUES ('2015-06-03 21:05:23', '2015-06-03 21:05:23')
(0.2ms) COMMIT
=> #<Owner id: 1, name: nil, created_at: "2015-06-03 21:05:23", updated_at: "2015-06-03 21:05:23">
irb(main):005:0> o.create_dog
(0.1ms) BEGIN
SQL (0.2ms) INSERT INTO `dogs` (`owner_id`, `created_at`, `updated_at`) VALUES (1, '2015-06-03 21:05:27', '2015-06-03 21:05:27')
(0.3ms) COMMIT
Dog Load (0.2ms) SELECT `dogs`.* FROM `dogs` WHERE `dogs`.`owner_id` = 1 LIMIT 1
=> #<Dog id: 1, owner_id: 1, created_at: "2015-06-03 21:05:27", updated_at: "2015-06-03 21:05:27">
irb(main):006:0> o.update name: 'George'
(0.2ms) BEGIN
SQL (0.5ms) UPDATE `owners` SET `name` = 'George', `updated_at` = '2015-06-03 21:05:34' WHERE `owners`.`id` = 1
(6.4ms) COMMIT
=> true
Next lets try again with User has_one Car which does use activeuuid. Our Car record should not be touched when updating the Owner.
u = User.create
(0.1ms) BEGIN
SQL (0.2ms) INSERT INTO `users` (`id`, `created_at`, `updated_at`) VALUES (x'69704d2f29cd4bc484fa9545b8c54a55', '2015-06-03 21:04:54', '2015-06-03 21:04:54')
(0.2ms) COMMIT
=> #<User id: #<UUID:0x3ff7ae5768f0 UUID:69704d2f-29cd-4bc4-84fa-9545b8c54a55>, name: nil, created_at: "2015-06-03 21:04:54", updated_at: "2015-06-03 21:04:54">
irb(main):002:0> c = u.create_car
(0.1ms) BEGIN
SQL (0.2ms) INSERT INTO `cars` (`id`, `user_id`, `created_at`, `updated_at`) VALUES (x'f92659de32814c7f8e05d95bc13fab72', x'69704d2f29cd4bc484fa9545b8c54a55', '2015-06-03 21:05:03', '2015-06-03 21:05:03')
(0.3ms) COMMIT
Car Load (0.2ms) SELECT `cars`.* FROM `cars` WHERE `cars`.`user_id` = x'69704d2f29cd4bc484fa9545b8c54a55' LIMIT 1
=> #<Car id: #<UUID:0x3ff7adb9276c UUID:f92659de-3281-4c7f-8e05-d95bc13fab72>, user_id: #<UUID:0x3ff7ae5768f0 UUID:69704d2f-29cd-4bc4-84fa-9545b8c54a55>, make: nil, created_at: "2015-06-03 21:05:03", updated_at: "2015-06-03 21:05:03">
irb(main):003:0> u.update name: 'George'
(0.2ms) BEGIN
SQL (0.4ms) UPDATE `users` SET `id` = x'69704d2f29cd4bc484fa9545b8c54a55', `name` = 'George', `updated_at` = '2015-06-03 21:05:15' WHERE `users`.`id` = x'69704d2f29cd4bc484fa9545b8c54a55'
######################################
SQL (0.2ms) UPDATE `cars` SET `id` = x'f92659de32814c7f8e05d95bc13fab72', `user_id` = x'69704d2f29cd4bc484fa9545b8c54a55', `updated_at` = '2015-06-03 21:05:15' WHERE `cars`.`id` = x'f92659de32814c7f8e05d95bc13fab72'
######################################
(6.2ms) COMMIT
=> true
From the logs we can see that the Car had its id and user_id updated along with the timestamps.
Has anyone else experienced this problem or come up with a fix?
The text was updated successfully, but these errors were encountered:
There is currently an issue on rails 4.2 and mysql where children of a has_one relationship are having their UUID updated at the same time as the parent. The strange thing is that a mysql
UPDATE
query is run overwriting the exact same data.To replicate the issue I have created a dummy app with a failing test suite. In the example we have Owner has_one Dog which does not use activeuuid and displays the rails default behaviour. We also have User has_one Car which does use uuid.
If we first take Owner has_one Dog we can confirm that the
Dog
record is never touched when updating theOwner
.Next lets try again with User has_one Car which does use activeuuid. Our
Car
record should not be touched when updating theOwner
.From the logs we can see that the
Car
had itsid
anduser_id
updated along with the timestamps.Has anyone else experienced this problem or come up with a fix?
The text was updated successfully, but these errors were encountered: