I have two AR models in a one-to-many relationship.
class Feed < ActiveRecord::Base
belongs_to :channel, :counter_cache => true
end
class Channel
has_many :feeds
end
I need to move a feed to a different channel. This works, except the
feeds_counter cache is not changed for the ‘to’ channel. What do I need
to do
differently?
old_channel = …
new_channel = …
f = old_channel.feeds[0]
old_channel.feeds.delete(f)
new_channel.feeds << f
Initially, there is one feed in each channel. old_channel.feeds_count
is zero
(Yeah!), but new_channel.feeds_count is still one (Boo!).
What to do differently?
TIA,
Jeffrey