Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reify method #427

Merged
merged 1 commit into from
Oct 1, 2014
Merged

Fix reify method #427

merged 1 commit into from
Oct 1, 2014

Conversation

vinh0604
Copy link
Contributor

When I drop a column in the model, i.e. address add replace it with the a association named address, I got the following exception:

ActiveModel::MissingAttributeError: can't write unknown attribute `address'
  from .../vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.9/lib/active_record/attribute_methods/write.rb:47:in `write_attribute'
  from .../vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.9/lib/active_record/attribute_methods/dirty.rb:70:in `write_attribute'
  from .../vendor/bundle/ruby/2.1.0/gems/enumerize-0.8.0/lib/enumerize/activerecord.rb:51:in `write_attribute'
  from .../vendor/bundle/ruby/2.1.0/gems/activerecord-4.0.9/lib/active_record/attribute_methods.rb:359:in `[]='
  from .../vendor/bundle/ruby/2.1.0/gems/paper_trail-3.0.5/lib/paper_trail/version_concern.rb:152:in `block (2 levels) in reify'
  from .../vendor/bundle/ruby/2.1.0/gems/paper_trail-3.0.5/lib/paper_trail/version_concern.rb:150:in `each'
  from .../vendor/bundle/ruby/2.1.0/gems/paper_trail-3.0.5/lib/paper_trail/version_concern.rb:150:in `block in reify'
  from .../vendor/bundle/ruby/2.1.0/gems/paper_trail-3.0.5/lib/paper_trail/version_concern.rb:225:in `call'
  from .../vendor/bundle/ruby/2.1.0/gems/paper_trail-3.0.5/lib/paper_trail/version_concern.rb:225:in `without_identity_map'
  from .../vendor/bundle/ruby/2.1.0/gems/paper_trail-3.0.5/lib/paper_trail/version_concern.rb:117:in `reify'

It's because the reify method use model.respond_to?("#{k}=") rather than model.has_attribute?(k), so it could cause exception if I define a method named address= as well.

This pull request is to fix this error

Handle case old version has attribute with same name with current model setter
@batter batter added this to the 3.1.0 milestone Sep 29, 2014
@batter
Copy link
Collaborator

batter commented Oct 1, 2014

Good call, I'll merge this in shortly.

batter added a commit that referenced this pull request Oct 1, 2014
Close #427; Fix reify method with regards to attribute assignment
@batter batter merged commit d5a8033 into paper-trail-gem:master Oct 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants