Itβs not easy for me to get the updated update_at column to update the casino model, which has all kinds of amenities through CasinoAmenity. The casino updated_at column is updated properly when adding amenities, but not when they are removed.
Here are my (simplified) models:
casino.rb
class Casino < ActiveRecord::Base has_many :amenity_casino, :dependent => :destroy has_many :amenities, :through => :amenity_casino end
amenity_casino.rb
class AmenityCasino < ActiveRecord::Base belongs_to :casino, :touch => true belongs_to :amenity, :touch => true end
amenity.rb
class Amenity < ActiveRecord::Base has_many :amenity_casinos, :dependent => :destroy has_many :casinos, :through => :amenity_casinos end
Now to the console. Checking the start time of update_at.
> Casino.find(5).updated_at => Wed, 30 Jan 2013 00:30:04 UTC +00:00
Adding amenities to the casino.
> Casino.find(5).amenities << Amenity.first => [#<Amenity id: 1, name: "asdf", weight: "", created_at: "2012-11-10 02:29:14", updated_at: "2013-01-30 01:29:14", description: "asdf">]
Confirmation that the association has been stored in the database
> Casino.find(5).amenities => [#<Amenity id: 1, name: "asdf", weight: "", created_at: "2012-11-10 02:29:14", updated_at: "2013-01-30 01:29:14", description: "asdf">]
We see that the update_at time for this casino has changed, as expected.
> Casino.find(5).updated_at => Wed, 30 Jan 2013 01:29:14 UTC +00:00
Now remove this service from the casino.
> Casino.find(5).amenities = [] => []
Now make sure it hits the database perfectly
> Casino.find(5).amenities => []
Now you can check the updated_at column for the casino ...
> Casino.find(5).updated_at => Wed, 30 Jan 2013 01:29:14 UTC +00:00
As you can see, this is the same as before we removed the amenities from the casino. I also tried the before_destroy filter on AmenityCasino to touch the casino, but that didn't seem to help.
I would like to hear if there are any solutions here. If that matters, I use ActiveAdmin to manage everything.
Rails Version - 3.2.11