1
0
Fork 0
mirror of https://github.com/paper-trail-gem/paper_trail.git synced 2022-11-09 11:33:19 -05:00

Update has-many-through patch in README.

This commit is contained in:
Andy Stewart 2011-11-25 08:54:22 +01:00
parent bafdc5b017
commit 0e742b124a

View file

@ -437,20 +437,24 @@ But none of these will:
>> @book.author_ids = [@solzhenistyn.id, @dostoyevsky.id] >> @book.author_ids = [@solzhenistyn.id, @dostoyevsky.id]
>> @book.authors = [] >> @book.authors = []
Having said that, you can apparently get all these working (I haven't tested it myself) with this [monkey patch](http://stackoverflow.com/questions/2381033/how-to-create-a-full-audit-log-in-rails-for-every-table/2381411#2381411): Having said that, you can apparently get all these working (I haven't tested it myself) with this patch:
# In config/initializers/core_extensions.rb or lib/core_extensions.rb # In config/initializers/active_record_patch.rb
ActiveRecord::Associations::HasManyThroughAssociation.class_eval do module ActiveRecord
def delete_records(records) # = Active Record Has Many Through Association
klass = @reflection.through_reflection.klass module Associations
records.each do |associate| class HasManyThroughAssociation < HasManyAssociation #:nodoc:
klass.destroy_all(construct_join_attributes(associate)) alias_method :original_delete_records, :delete_records
def delete_records(records, method)
method ||= :destroy
original_delete_records(records, method)
end
end end
end end
end end
The difference is the call to `destroy_all` instead of `delete_all` in [the original](http://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/has_many_through_association.rb#L76-81). See [issue 113](https://github.com/airblade/paper_trail/issues/113) for a discussion about this.
There may be a way to store authorship versions, probably using association callbacks, no matter how the collection is manipulated but I haven't found it yet. Let me know if you do. There may be a way to store authorship versions, probably using association callbacks, no matter how the collection is manipulated but I haven't found it yet. Let me know if you do.
@ -689,6 +693,7 @@ Many thanks to:
* [Nicholas Thrower](https://github.com/throwern) * [Nicholas Thrower](https://github.com/throwern)
* [Benjamin Curtis](https://github.com/stympy) * [Benjamin Curtis](https://github.com/stympy)
* [Peter Harkins](https://github.com/pushcx) * [Peter Harkins](https://github.com/pushcx)
* [Mohd Amree](https://github.com/amree)
## Inspirations ## Inspirations