Ruby on rails 如何使用“where”过滤Rails中的非属性值?

Ruby on rails 如何使用“where”过滤Rails中的非属性值?,ruby-on-rails,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 4,在我的成员模型中,我有这样一种方法来计算值: def currentreg if self.currentaward self.send(self.currentaward.downcase).regdate end end 数据库如下所示: # id :integer not null, primary key # awardunit_id :integer # name :string(255) # a

在我的成员模型中,我有这样一种方法来计算值:

def currentreg
 if self.currentaward
  self.send(self.currentaward.downcase).regdate
 end
end
数据库如下所示:

#  id              :integer          not null, primary key
#  awardunit_id    :integer
#  name            :string(255)
#  address         :string(255)
#  district        :string(255)
#  gender          :string(255)
#  dob             :date
#  contact         :string(255)
#  email           :string(255)
#  operator        :string(255)
#  entrylvl        :string(255)
#  guardianname    :string(255)
#  guardianaddress :string(255)
#  guardiancontact :string(255)
#  guardianemail   :string(255)
#  currentaward    :string(255)

我想知道如何使用where方法过滤currentreg?

它是一个计算值,不存储在数据库中,ActiveRecord用于查询数据库。您可以使用ruby数组方法筛选数据集,但效率不高。@EApubs AFAIK我们无法使用active record查询方法获取方法值,相反,您可以在模型中使用任何rails回调调用该方法。您不能使用where筛选currentreg,因为它不是数据库中的值。。。但是,您可以在一定程度上过滤当前奖励,currentreg的值似乎是根据。。。我不建议尝试按currentaward中包含的值进行筛选,但您可以使用where。。。如果您想按currentreg的实际值进行筛选,您仍然需要进行选择,但是如果记录较少,那么选择应该会快一点。。。尽管如此,这样的努力还是不值得的