mobility icon indicating copy to clipboard operation
mobility copied to clipboard

using attribute_methods in combination with select raises MissingAttributeError

Open jnylen opened this issue 3 years ago • 1 comments

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.

jnylen avatar Apr 11 '22 03:04 jnylen

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.

shioyama avatar May 02 '22 02:05 shioyama