Add documentation for custom association name.

This commit is contained in:
Andy Stewart 2011-07-23 17:04:40 +01:00
parent e93ddeac96
commit 05f15be700
2 changed files with 13 additions and 0 deletions

View File

@ -23,6 +23,7 @@ There's an excellent [Railscast on implementing Undo with Paper Trail](http://ra
* No configuration necessary.
* Stores everything in a single database table by default (generates migration for you), or can use separate tables for separate models.
* Supports custom version classes so different models' versions can have different behaviour.
* Supports custom name for versions association.
* Thoroughly tested.
* Threadsafe.
@ -327,6 +328,17 @@ This allows you to store each model's versions in a separate table, which is use
Alternatively you could store certain metadata for one type of version, and other metadata for other versions.
You can also specify a custom name for the versions association. This is useful if you already have a `versions` method on your model. For example:
class Post < ActiveRecord::Base
has_paper_trail :versions_association_name => :paper_trail_versions
# Existing versions method. We don't want to clash.
def versions
...
end
end
## Associations

View File

@ -18,6 +18,7 @@ module PaperTrail
# Values are objects or procs (which are called with `self`, i.e. the model with the paper
# trail). See `PaperTrail::Controller.info_for_paper_trail` for how to store data from
# the controller.
# :versions_association_name the name to use for the versions association. Default is `:versions`.
def has_paper_trail(options = {})
# Lazily include the instance methods so we don't clutter up
# any more ActiveRecord models than we have to.