Given the following controller code
def update
params[:image][:contributor_ids] ||= []
params[:image][:category_ids] ||= []
@image = Image.find( params[:id] )
if @image.update_attributes params[:image]
redirect_to session[:return_to]
else
render :edit
end
end
And the following image model
class Image < ActiveRecord::Base
has_many :category_links, :as => :categorizable, :dependent => :destroy
has_many :categories, :through => :category_links
has_many :contributions, :as => :contributable, :dependent => :destroy
has_many :contributors, :through => :contributions
# .... omitted for clarity
end
When the update_attributes gets called with just the associations being changed
ActiveRecord does not change the updated_at column – why is that and how to change that behavior ?
I think this is happening because when you have a N:N relation and you update that relation, you are actually creating/modifying/deleting records in the join table (in this case,
contributionsorcategory_links), and not actually updating the@imageinstance itself.