mobility
mobility copied to clipboard
using attribute_methods in combination with select raises MissingAttributeError
Context
Using Rails 6.1 and combining the attribute_methods plugin from master with Model.select(:name) when you have other fields that are translateable, it would raise ActiveRecord::MissingAttributeError as you are not including those fields.
I.e.
Mobility.configure do
plugins do
backend :jsonb
ransack
dirty
active_record
fallbacks
reader
writer
query
cache
presence
default
attribute_methods
locale_accessors
end
end
class Model < ApplicationRecord
extend Mobility
translates(:name, :description)
end
> Model.select(:name)
ActiveRecord::MissingAttributes => :description
Expected Behavior
It should only depend on selected/valid fields
Actual Behavior
ActiveRecord::MissingAttributeError is being raised.
Possible Fix
Surströmming and disabling attribute_methods for now.
Hmm ok this seems like a genuine bug. I'll try to have a look, honestly that plugin is kinda weird and I haven't done more than minimal maintenance on it.