Skip to content
This repository

Bypass validations on Tolk::Sync#sync_phrases #29

Merged
merged 1 commit into from about 1 year ago

2 participants

Lonnie Warpup Thomas Darde
Lonnie Warpup

When updating the primary_updated flag on secondary phrases for which
the primary phrase has been updated, use a direct-to-DB call to avoid
invoking possibly heavy ActiveRecord validations or triggering an
exeption when the variables used in the phrase change. (fixes #28)

Lonnie Warpup Bypass validations on Tolk::Sync#sync_phrases
When updating the primary_updated flag on secondary phrases for which
the primary phrase has been updated, use a direct-to-DB call to avoid
invoking possibly heavy ActiveRecord validations or triggering an
exeption when the variables used in the phrase change. (fixes #28)
3a72878
Thomas Darde thomasdarde merged commit f45e1d6 into from March 04, 2013
Thomas Darde thomasdarde closed this March 04, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Feb 11, 2013
Lonnie Warpup Bypass validations on Tolk::Sync#sync_phrases
When updating the primary_updated flag on secondary phrases for which
the primary phrase has been updated, use a direct-to-DB call to avoid
invoking possibly heavy ActiveRecord validations or triggering an
exeption when the variables used in the phrase change. (fixes #28)
3a72878
This page is out of date. Refresh to see the latest.
3  app/models/tolk/translation.rb
@@ -17,7 +17,6 @@ class Translation < ActiveRecord::Base
17 17
 
18 18
     attr_accessible :phrase_id, :locale_id, :text, :primary_updated, :previous_text, :locale, :phrase
19 19
 
20  
-    attr_accessor :force_set_primary_update
21 20
     before_save :set_primary_updated
22 21
 
23 22
     before_save :set_previous_text
@@ -138,7 +137,7 @@ def fix_text_type
138 137
     end
139 138
 
140 139
     def set_primary_updated
141  
-      self.primary_updated = self.force_set_primary_update ? true : false
  140
+      self.primary_updated = false
142 141
       true
143 142
     end
144 143
 
8  lib/tolk/sync.rb
@@ -38,7 +38,6 @@ def flat_hash(data, prefix = '', result = {})
38 38
 
39 39
       def sync_phrases(translations)
40 40
         primary_locale = self.primary_locale
41  
-        secondary_locales = self.secondary_locales
42 41
 
43 42
         # Handle deleted phrases
44 43
         translations.present? ? Tolk::Phrase.destroy_all(["tolk_phrases.key NOT IN (?)", translations.keys]) : Tolk::Phrase.destroy_all
@@ -54,12 +53,7 @@ def sync_phrases(translations)
54 53
 
55 54
           if translation.changed? && !translation.new_record?
56 55
             # Set the primary updated flag if the primary translation has changed and it is not a new record.
57  
-            secondary_locales.each do |locale|
58  
-              if existing_translation = existing_phrase.translations.detect {|t| t.locale_id == locale.id }
59  
-                existing_translation.force_set_primary_update = true
60  
-                existing_translation.save!
61  
-              end
62  
-            end
  56
+            existing_phrase.translations.update_all({ :primary_updated => true }, Tolk::Translation.arel_table[:locale_id].not_eq(primary_locale.id))
63 57
           end
64 58
 
65 59
           translation.primary = true
3  test/unit/format_test.rb
@@ -124,8 +124,7 @@ def test_bulk_update_saves_unchanged_record
124 124
     @spanish.save!
125 125
 
126 126
     spanish_string = @spanish.translations.first
127  
-    spanish_string.force_set_primary_update = true
128  
-    spanish_string.save!
  127
+    spanish_string.update_column(:primary_updated, true)
129 128
     assert spanish_string.primary_updated?
130 129
 
131 130
     @spanish.reload
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.