Skip to content

Commit

Permalink
Have attributes_builder handle MIQ virtual_attributes
Browse files Browse the repository at this point in the history
This overwrites the default method for this by adding an additional
check to the proc that is defined with the AttributeSet::Builder to
check to see if the key should be provided a default from the
`_default_attributes` hash to not only check to see if it is a column
from the database, but also a virtual_attribute.

The functionality added by:

rails/rails@3e37a8b#diff-6c8fd220c92c2b25aa29891b59d00c04

was meant to help vanilla Rails' "virtual attributes" by assigning a
default value on model instantiation.  This is not what used to be done
for any attributes (database or otherwise) besides the primary key for
that model.  What this does is includes `virtual_attributes` as
attributes that aren't defined with a default value, along the database
column attributes.
  • Loading branch information
NickLaMuro committed Jan 6, 2017
1 parent fcf5dbd commit 317e111
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/extensions/ar_virtual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ def virtual_attribute_names
end
end

def attributes_builder
@attributes_builder ||= ::ActiveRecord::AttributeSet::Builder.new(attribute_types, primary_key) do |name|
unless columns_hash.key?(name) || virtual_attribute?(name)
_default_attributes[name].dup
end
end
end

private

def load_schema!
Expand Down

0 comments on commit 317e111

Please sign in to comment.