Open 4ndypanda opened 8 months ago
A tricky thing is if people do want virtual attributes with a ciphertext virtual attribute (not from an ActiveRecord column)
class User < ActiveRecord::Base
# This is never saved to the database, idk why one
# would want this though.
attribute :foo_ciphertext
has_encrypted :foo
end
This is one case where it probably should still show up in the attribute methods attributes
, attribute_names
, has_attribute?
.
Hey @4ndypanda, will take a look at this as part of 2.0 since it's a breaking change.
I was also annoyed by this issue since I constantly run into
ActiveModel::MissingAttributeError
when doing stuff likeWhat are your thoughts on overriding
#init_with_attributes
in ActiveRecord::Core? Before ever setting the@attributes
instance variable for the model, we could filter and check if the ciphertext attribute is presentI was trying to see where else to do it. The caller here takes the
attributes
from the database result set and merges it with theself.class._default_attributes
that includes the virtual attributes.Overriding
attributes_builder.build_from_database
(source) is another option.What are your thoughts?