Skip to content
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

TypeError: Cannot visit Mobility::Arel::Nodes::Json when using i18n scope #320

Closed
23tux opened this issue Mar 5, 2019 · 2 comments
Closed

Comments

@23tux
Copy link

23tux commented Mar 5, 2019

When trying to use the i18n helper, an error is raised TypeError: Cannot visit Mobility::Arel::Nodes::Json

Context

We are using mobility with MySQL 5.7 and JSON columns and ActiveRecord 5.2.2. When I try to use the i18n helper, I get an exception:

[1] pry(main)> Product.i18n.find_by(name: "Shirt")
TypeError: Cannot visit Mobility::Arel::Nodes::Json
from /usr/local/bundle/gems/arel-9.0.0/lib/arel/visitors/reduce.rb:21:in `rescue in visit'
Caused by NoMethodError: undefined method `visit_Mobility_Arel_Nodes_Json' for #<Arel::Visitors::MySQL:0x00007fead9544fe0>
from /usr/local/bundle/gems/arel-9.0.0/lib/arel/visitors/reduce.rb:15:in `visit'

My schema looks like this:

create_table "products", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t|
  t.json "name"
end

product.rb model:

class Product < ApplicationRecord
  extend Mobility
  translates :name
end

Expected Behavior

Return results for multiple languages. The SQL Query could look something like this

SELECT `products`.* FROM `products` WHERE ((name->'$.de' = 'Shirt') OR (name->'$.fr' = 'Shirt'))

Actual Behavior

An error is raised.

@shioyama shioyama closed this as completed Mar 5, 2019
@shioyama
Copy link
Owner

shioyama commented Mar 5, 2019

Mobility does not (yet) support JSON with MySQL. There are issues about this and I believe it is mentioned in the readme as well.

@shioyama
Copy link
Owner

shioyama commented Mar 5, 2019

See also #271.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants