Skip to content

Commit

Permalink
Avoid multiple updates
Browse files Browse the repository at this point in the history
There was a bug where the extension table whas being updated once for each extension column on the table because an after_save callback was being added for each one. This commit fixes that making it just one update.
  • Loading branch information
oboxodo committed Apr 26, 2008
1 parent 6b40bd4 commit 441d663
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions lib/acts_as_extensible.rb
Expand Up @@ -48,23 +48,24 @@ def #{prefix}#{column}#{suffix}
eos
end

class_eval <<-eos
after_save :update_#{model}_attributes
protected
def update_#{model}_attributes
build_#{model} if #{model}.nil?
#{model}.save
end
eos

class_eval <<-eos
def column_for_attribute_#{prefix}#{column}
#{model_class}.columns_hash["#{column}"]
end
eos
end

class_eval <<-eos
after_save :update_#{model}_attributes
protected
def update_#{model}_attributes
build_#{model} if #{model}.nil?
#{model}.save
end
eos

include ActsAsExtensible::ColumnDelegation::InstanceMethods
end

Expand Down

0 comments on commit 441d663

Please sign in to comment.