ruby-on-railsrubymobility

Accessing "real_field_non_translated"? - Mobility


Is there a way, via ActiveRecord, to access the "real_field" (let's say)?

For example. If I have a Model Company and do Company.create(name: "My Company Name") (with I18n.locale = :en), that name value won't be saved in the Company record, but in the Mobility table for the string.

So doing Company.last will return

#<Company id: 5, name: nil>

But doing Company.last.name will return My Company Name (assuming the locale is set properly)

Is there a way to do something like Company.last.real_name that would give me the actual value of the record? In this case nil. I would also like to have a real_name=.

mobility (0.4.2) i18n (>= 0.6.10, < 0.10) request_store (~> 1.0)

Backend: key_value


Solution

  • Try this:

    Company.last.read_attribute :name
    

    Or this:

    Company.last.name_before_type_cast