i have serious problem with touch directive in Rails association.
It always edit updated_at timestamp. That is weird because when associated object is not changed, always update timestamp.
Have Place
class Place < ActiveRecord::Base
has_one :location, inverse_of: :place, dependent: :destroy
attr_accessible :name
attr_accessible :location_attributes
accepts_nested_attributes_for :location
end
and Location
class Location < ActiveRecord::Base
belongs_to :place, inverse_of: :location, touch: true
attr_accessible :number, :street, :locality, :region, :postal_code, :country, :description, :description_en, :latitude, :longitude
attr_accessible :place_id
validates :place, presence: true
validates :number, presence: true
validates :street, presence: true
validates :locality, presence: true
validates :postal_code, presence: true, postal_code: { country: :sk }
validates :latitude, presence: true, numericality: true, allow_nil: true
validates :longitude, presence: true, numericality: true, allow_nil: true
end
When i load and save existed place without changes:
Place.last.save # changed? == false
it automaticaly edit updated_at
SQL (0.4ms) UPDATE `places` SET `updated_at` = '2012-11-18 20:38:48' WHERE `places`.`id` = 490
Do someone any experience with this how to fix it or something?
Uses Rails 3.2.9 and MySQL (mysql2 adapter)
EDIT:
Location.last.save changed to Place.last.save. It was mistake.