-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include the table name in the with_x_translation #15
base: master
Are you sure you want to change the base?
Include the table name in the with_x_translation #15
Conversation
I like it! |
p = Post.create!(:title_translations => { "en" => "Alice in Wonderland", "fr" => "Alice au pays des merveilles" }) | ||
Tag.create!(:title_translations => { "en" => "A Tag", "fr" => "Un tag" }, post: p) | ||
I18n.with_locale(:en) do | ||
assert_equal p.title_en, Post.tagged("A Tag").first.try(:title) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p = Post.create!(:title_translations => { "en" => "Alice in Wonderland", "fr" => "Alice au pays des merveilles" }) | |
Tag.create!(:title_translations => { "en" => "A Tag", "fr" => "Un tag" }, post: p) | |
I18n.with_locale(:en) do | |
assert_equal p.title_en, Post.tagged("A Tag").first.try(:title) | |
post = Post.create!(:title_translations => { "en" => "Alice in Wonderland", "fr" => "Alice au pays des merveilles" }) | |
Tag.create!(:title_translations => { "en" => "A Tag", "fr" => "Un tag" }, post: post) | |
I18n.with_locale(:en) do | |
assert_equal post.title_en, Post.tagged("A Tag").first.title |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be happy to make that change, but I originally went with p
because that's what was used in all the tests. I think a change like that should be a separate PR and fix update all existing tests in one pass. What do you think?
This is to prevent a possible ambiguous column error when the model is joined with another model having the same translated column name.
3675cee
to
823019c
Compare
Hey @frantisekrokusek, I rebased this PR against the main branch. It seems like travis is not setup to run the tests anymore. Are you planning on switching to another CI tool setup? |
When generating
with_#{attr_name}_translation
methods, include the table name in the query. This is to prevent a possible ambiguous column error when the model is joined with another model having the same translated column name.For example:
Calling
Post.tagged("abc")
would produceActiveRecord::StatementInvalid: PG::AmbiguousColumn: ERROR: column reference "title_translations" is ambiguous
because the table name was not included in the query. I added a test covering that case.