Repository is archived
No commit activity in last 3 years
No release in over 3 years
Provides a concern for monitoring changes to has_many and has_many_and_belongs_to associations using ActiveModel::Dirty.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 3.2.1
 Project Readme

Unmaintained¶ ↑

This gem is unmaintained.

DirtyAssociations¶ ↑

Monitors changes to has_many and has_and_belongs_to_many associations using ActiveModel::Dirty.

Usage¶ ↑

Include DirtyAssociations concern in your model.

include DirtyAssociations

Call monitor_association_changes method after has_many.

has_many :foos
monitor_association_changes :foos

Check one of the following methods to see if the relation has changed:

  • changes

  • changed

  • previous_changes

  • [singularized_association_name]_ids_changed?

  • [singularized_association_name]_ids_previously_changed?

    bar.foos = [ Foo.find(42) ] # or you can use the foo_ids setter
    bar.changes # { "foo_ids" => [[5], [42]] }
    bar.changed # [ "foo_ids" ]
    bar.foo_ids_changed? # true
    bar.foo_ids_previously_changed? # false
    
    bar.save
    bar.previous_changes # { "foo_ids" => [[5], [42]] }
    bar.foo_ids_changed? # false
    bar.foo_ids_previously_changed? # true