You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm just getting started with Mobility. I found that to use the container strategy on postgres and preserve my existing columns it was best to use 1.3.0.rc1. Rails 7.1.3
Document.last.title#=> "Document Title in fallback column"title_es="hablas espagnol"Mobility.with_locale(:es){document.title=title_esputsdocument.title}#=> "hablas espagnol"
and to have title_es stored in the translations column of the Document record.
Actual Behavior
Here's my test script to reproduce
document=Document.lastputsdocument.titletitle_es="hablas espagnol"Mobility.with_locale(:es){document.title=title_esputsdocument.title}# => mobility-1.3.0.rc1/lib/mobility/backends/active_record/pg_hash.rb:26:in `[]=': string not matched (IndexError)
The good news for me is I should be using :container backend and not :jsonb backend which resolves my issue.
I'm not 100% sure but it seems that the above still holds true for a :jsonb backend with a column_fallback true plugin.
This failing test reveals the issue which could be added if this is intended behavior.
# spec/mobility/plugins/active_record/column_fallback_spec.rbcontext"column_fallback: true with jsonb backend"doplugin_setup:slug,column_fallback: truebeforedotranslatesmodel_class,:slug,backend: :jsonb,column_fallback: trueendit"reads/writes from/to backend if locale is not I18n.default_locale"doinstance.send(:write_attribute,:slug,"foo")Mobility.with_locale(:fr)doexpect(listener).toreceive(:read).with(:fr,any_args).and_return("bar")expect(instance.slug).toeq("bar")expect(listener).toreceive(:write).with(:fr,"baz",any_args)instance.slug="baz"endendend
Correct me but in documentation jsonb column for for your translates :title
should be added as add_column(:documents, :title, :jsonb, default: {})
not the add_column :documents, :translations, :jsonb, default: {}
I'm just getting started with Mobility. I found that to use the container strategy on postgres and preserve my existing columns it was best to use 1.3.0.rc1. Rails 7.1.3
Context
My Document model has an existing title column with a default locale of english.
Expected Behavior
and to have
title_es
stored in thetranslations
column of the Document record.Actual Behavior
Here's my test script to reproduce
Possible Fix
Spelunking in pg_hash, here's what I find
translations[locale.to_s] = value
has an IndexError becausetranslations
is returning the value of the column fallback:title
attribute.A very naive fix would be to change translations but I know there's a lot more going on here.
The text was updated successfully, but these errors were encountered: