svenfuchs/globalize3 — Issue #76: 0.2.0.beta4 inserts translation with null values before updating
Author: sauberia
Created: 2011-10-21 00:27:55+00:00
State: open

Whereas 0.1.0 inserts a translation with the correct values, the newer version first inserts a translation with null values and then updates that translation with its proper values.

This stops me from disallowing null values for a translation field that shouldn't have null values.

Is this the intended behaviour?

Example below:

class Thing < ActiveRecord::Base
translates :name
end

config.i18n.fallbacks = { :fr => :en }

Thing.create! :name => 'cat'

---

Rails 3.0.10
Globalize3 0.2.0.beta4

SQL (0.1ms) BEGIN
SQL (0.2ms) SHOW TABLES
SQL (0.6ms) describe `things`
AREL (0.1ms) INSERT INTO `things` (`updated_at`, `created_at`) VALUES ('2011-10-21 00:11:13', '2011-10-21 00:11:13')
SQL (0.6ms) describe `thing_translations`
AREL (0.2ms) INSERT INTO `thing_translations` (`updated_at`, `text`, `locale`, `thing_id`, `created_at`, `name`) VALUES ('2011-10-21 00:11:13', NULL, 'en', 1, '2011-10-21 00:11:13', NULL)
Thing::Translation Load (0.2ms) SELECT `thing_translations`.* FROM `thing_translations` WHERE `thing_translations`.`locale` = 'en' AND (`thing_translations`.thing_id = 1) LIMIT 1
AREL (0.1ms) UPDATE `thing_translations` SET `updated_at` = '2011-10-21 00:11:13', `name` = 'cat' WHERE `thing_translations`.`id` = 1
Thing::Translation Load (0.1ms) SELECT `thing_translations`.* FROM `thing_translations` WHERE `thing_translations`.`id` = 1 LIMIT 1
Thing::Translation Load (0.1ms) SELECT `thing_translations`.* FROM `thing_translations` WHERE (`thing_translations`.thing_id = 1)
SQL (0.3ms) COMMIT

---

Rails 3.0.10
Globalize3 0.1.0

SQL (0.1ms) BEGIN
AREL (0.2ms) INSERT INTO `things` (`updated_at`, `created_at`) VALUES ('2011-10-21 00:13:41', '2011-10-21 00:13:41')
Thing::Translation Load (0.2ms) SELECT `thing_translations`.* FROM `thing_translations` WHERE `thing_translations`.`locale` = 'en' AND (`thing_translations`.thing_id = 3) LIMIT 1
AREL (0.1ms) INSERT INTO `thing_translations` (`text`, `locale`, `created_at`, `updated_at`, `name`, `thing_id`) VALUES (NULL, 'en', '2011-10-21 00:13:41', '2011-10-21 00:13:41', 'cat', 3)
Thing::Translation Load (0.2ms) SELECT `thing_translations`.* FROM `thing_translations` WHERE (`thing_translations`.thing_id = 3)
SQL (0.3ms) COMMIT