Revision a6810fc6
Added by Joseph Magen almost 11 years ago
- ID a6810fc666689e1439f99ffa56170db285cfb657
app/models/concerns/host_common.rb | ||
---|---|---|
has_many :lookup_values, :finder_sql => Proc.new { %Q{ SELECT lookup_values.* FROM lookup_values WHERE (lookup_values.match = '#{lookup_value_match}') } }, :dependent => :destroy
|
||
# See "def lookup_values_attributes=" under, for the implementation of accepts_nested_attributes_for :lookup_values
|
||
accepts_nested_attributes_for :lookup_values
|
||
end
|
||
|
||
# Replacement of accepts_nested_attributes_for :lookup_values,
|
||
# to work around the lack of `host_id` column in lookup_values.
|
||
def lookup_values_attributes= lookup_values_attributes
|
||
lookup_values_attributes.each_value do |attribute|
|
||
attr = attribute.dup
|
||
if attr.has_key? :id
|
||
lookup_value = lookup_values.find attr.delete(:id)
|
||
if lookup_value
|
||
mark_for_destruction = ActiveRecord::ConnectionAdapters::Column.value_to_boolean attr.delete(:_destroy)
|
||
lookup_value.attributes = attr
|
||
mark_for_destruction ? lookup_values.delete(lookup_value) : lookup_value.save!
|
||
# Replacement of accepts_nested_attributes_for :lookup_values,
|
||
# to work around the lack of `host_id` column in lookup_values.
|
||
def lookup_values_attributes= lookup_values_attributes
|
||
lookup_values_attributes.each_value do |attribute|
|
||
attr = attribute.dup
|
||
if attr.has_key? :id
|
||
lookup_value = lookup_values.find attr.delete(:id)
|
||
if lookup_value
|
||
mark_for_destruction = ActiveRecord::ConnectionAdapters::Column.value_to_boolean attr.delete(:_destroy)
|
||
lookup_value.attributes = attr
|
||
mark_for_destruction ? lookup_values.delete(lookup_value) : lookup_value.save!
|
||
end
|
||
elsif !ActiveRecord::ConnectionAdapters::Column.value_to_boolean attr.delete(:_destroy)
|
||
LookupValue.create(attr.merge(:match => lookup_value_match))
|
||
end
|
||
elsif !ActiveRecord::ConnectionAdapters::Column.value_to_boolean attr.delete(:_destroy)
|
||
LookupValue.create(attr.merge(:match => lookup_value_match))
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
fixes #2812 - method lookup_values_attributes= not defined in Host::Managed (NameError)