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

ActiveRecord Jsonb backend - fallbacks: true does not work #648

Closed
testa19 opened this issue Aug 29, 2024 · 1 comment
Closed

ActiveRecord Jsonb backend - fallbacks: true does not work #648

testa19 opened this issue Aug 29, 2024 · 1 comment

Comments

@testa19
Copy link

testa19 commented Aug 29, 2024

Context

We started to use mobility for some existing tables. Decided not to remove the old field as there are queries that use the filed (we just save :en variant to the field in a before hook)

Falbacks do not work for jsonb backend.

 translates :title, backend: :jsonb, column_suffix: '_i18n', fallbacks: true

item = Item.find 3
=> #<Item:0x00000001094bd098
 id: 3,
 title: "Controller",
 primary_title: false,
 created_at: Tue, 08 Mar 2022 12:41:53.904284000 UTC +00:00,
 updated_at: Tue, 08 Mar 2022 12:41:53.904725000 UTC +00:00,
 title_i18n: {"en"=>"Controller"}>
I18n.with_locale(:en) { item.title }
=> "Controller"

item = Item.find 3
I18n.with_locale(:fi) { item.title }
=> nil
 translates :title, backend: :jsonb, column_suffix: '_i18n', fallbacks: { fi: :en }

item = Item.find 3
=> #<Item:0x00000001094bd098
 id: 3,
 title: "Controller",
 primary_title: false,
 created_at: Tue, 08 Mar 2022 12:41:53.904284000 UTC +00:00,
 updated_at: Tue, 08 Mar 2022 12:41:53.904725000 UTC +00:00,
 title_i18n: {"en"=>"Controller"}>
I18n.with_locale(:en) { item.title }
=> "Controller"

item = Item.find 3
I18n.with_locale(:fi) { item.title }
=> "Controller"

Expected Behavior

 translates :title, backend: :jsonb, column_suffix: '_i18n', fallbacks: true

item = Item.find 3
=> #<Item:0x00000001094bd098
 id: 3,
 title: "Controller",
 primary_title: false,
 created_at: Tue, 08 Mar 2022 12:41:53.904284000 UTC +00:00,
 updated_at: Tue, 08 Mar 2022 12:41:53.904725000 UTC +00:00,
 title_i18n: {"en"=>"Controller"}>
I18n.with_locale(:en) { item.title }
=> "Controller"

item = Item.find 3
I18n.with_locale(:fi) { item.title }
=> "Controller"

Actual Behavior

 translates :title, backend: :jsonb, column_suffix: '_i18n', fallbacks: true

item = Item.find 3
=> #<Item:0x00000001094bd098
 id: 3,
 title: "Controller",
 primary_title: false,
 created_at: Tue, 08 Mar 2022 12:41:53.904284000 UTC +00:00,
 updated_at: Tue, 08 Mar 2022 12:41:53.904725000 UTC +00:00,
 title_i18n: {"en"=>"Controller"}>
I18n.with_locale(:en) { item.title }
=> "Controller"

item = Item.find 3
I18n.with_locale(:fi) { item.title }
=> nil

Config

Mobility.configure do
  # PLUGINS
  plugins do
    backend :key_value

    active_record

    reader
    writer

    backend_reader

    query

    cache

    fallbacks

    presence


    locale_accessors

  end
end
@testa19
Copy link
Author

testa19 commented Sep 2, 2024

Ok, it was me being stupid - the fallback was turned off for the dev environment

@testa19 testa19 closed this as completed Sep 2, 2024
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

1 participant