型号:
class Location < ActiveRecord::Base
attr_accessible :longitude, :latitude, :radius, :name
has_many :statistics
end
class Statistic < ActiveRecord::Base
attr_accessible :stat_type_id, :updated, :count, :location_id
belongs_to :location
belongs_to :stat_type
end
class StatType < ActiveRecord::Base
attr_accessible :id, :name
has_many :statistics
end
我可以更新这样的记录:
statistic = @@location.statistics.build(:count => 1, :updated => updated, :stat_type_id => @@stat_type.id)
statistic.save
目前始终会创建新记录。但是,我想更改此设置,以便count
增加而不是赋值1
。
我知道increment
存在:http://apidock.com/rails/ActiveRecord/Persistence/increment但我不确定如何在我的情况下使用它(使用此JOIN)。我该如何使用它?
感谢。