0

我有一个 TourDet 模型,其中包含以下持久属性:

tdclientid
tdsuppid
tdpaxnos
tdpriceperpax

我在 TourDet 课程中也有以下内容

def tourval
  tdpaxnos * tdpricerperpax
end

我现在正在尝试执行以下操作:

 tdis = TourDet.find(:all, conditions: ['tdtourhdrid = 23'], group: [:tdsuppid,:tdclientid], select: ['tdsuppid,tdclientid,sum(tourval) as ttl'])

然而,rails 抱怨 Unknown column 'tourval'。

关于如何以另一种方式实现相同结果的任何想法?

我将 Rails 3.2 与 Ruby 1.9 和 MySQL 一起使用。

4

1 回答 1

0

据我了解您的应用程序,您不能tourval在查询中引用它,因为它是在 Ruby 中定义的,而不是在 MySQL 中。

这个怎么样?

tdis = TourDet.find(:all, conditions: ['tdtourhdrid = 23'], group: [:tdsuppid,:tdclientid], select: ['tdsuppid,tdclientid,sum(tdpaxnos*tdpricerperpax) as ttl'])
于 2012-05-18T14:39:45.460 回答