How can I make an aggregated property support ActiveRecord::Dirty semantics?

Posted by Eric on Stack Overflow See other posts from Stack Overflow or by Eric
Published on 2009-11-05T21:46:11Z Indexed on 2010/04/19 10:03 UTC
Read the original article Hit count: 204

Filed under:
|

I have an aggregated attribute which I want to be able ask about its _changed? ness, etc.

composed_of :range,
            :class_name => 'Range',
            :mapping => [ %w(range_begin begin), %w(range_end end)],
            :allow_nil => true

If I use the aggregation:

foo.range = 1..10

This is what I get:

foo.range                # => 1..10
foo.range_changed?       # NoMethodError
foo.range_was            # ditto
foo.changed              # ['range_begin', 'range_end']

So basically, I'm not getting ActiveRecord::Dirty semanitcs on aggregated attributes. Is there any way to do that? I'm not having a lot of luck with alias_attribute_with_dirty, etc.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activerecord