File tree 3 files changed +21
-1
lines changed
3 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ def translates(*attrs)
39
39
end
40
40
41
41
define_singleton_method "with_#{ attr_name } _translation" do |value , locale = I18n . locale |
42
- quoted_translation_store = connection . quote_column_name ( " #{ attr_name } #{ SUFFIX } ")
42
+ quoted_translation_store = connection . quote_table_name ( " #{ self . table_name } . #{ attr_name } #{ SUFFIX } ")
43
43
translation_hash = { "#{ locale } " => value }
44
44
45
45
if MYSQL_ADAPTERS . include? ( connection . adapter_name )
Original file line number Diff line number Diff line change 7
7
I18n . available_locales = [ :en , :fr ]
8
8
9
9
class Post < ActiveRecord ::Base
10
+ has_many :tags
10
11
translates :title , :body_1
12
+
13
+ scope :tagged , -> ( tag_title ) { joins ( :tags ) . merge ( Tag . with_title_translation ( tag_title ) ) }
14
+ end
15
+
16
+ class Tag < ActiveRecord ::Base
17
+ belongs_to :post
18
+ translates :title
11
19
end
12
20
13
21
class PostDetailed < Post
@@ -53,6 +61,10 @@ def create_table
53
61
t . column :body_1_translations , column_type
54
62
t . column :comment_translations , column_type
55
63
end
64
+ connection . create_table ( :tags , :force => true ) do |t |
65
+ t . column :title_translations , column_type
66
+ t . column :post_id , :integer
67
+ end
56
68
end
57
69
end
58
70
Original file line number Diff line number Diff line change @@ -206,6 +206,14 @@ def test_with_translation_relation
206
206
end
207
207
end
208
208
209
+ def test_with_translation_when_ambiguous_column
210
+ p = Post . create! ( :title_translations => { "en" => "Alice in Wonderland" , "fr" => "Alice au pays des merveilles" } )
211
+ Tag . create! ( :title_translations => { "en" => "A Tag" , "fr" => "Un tag" } , post : p )
212
+ I18n . with_locale ( :en ) do
213
+ assert_equal p . title_en , Post . tagged ( "A Tag" ) . first . try ( :title )
214
+ end
215
+ end
216
+
209
217
def test_with_interpolation_arguments
210
218
p = Post . create! ( :title_translations => { "en" => "Alice in %{where}" } )
211
219
I18n . with_locale ( :en ) do
You can’t perform that action at this time.
0 commit comments