如果JOIN表中存在值,则递增值

时间:2013-12-10 16:51:15

标签: ruby-on-rails ruby join increment

型号:

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)。我该如何使用它?

感谢。

0 个答案:

没有答案