我有三种模式:地点和特区;热点和特区;账户。
在我的工作地点模式中,我有:
has_many :hotspots
has_many :accounts, :foreign_key => :calledstationidclean, :through => :hotspots
我试图从每个地点账户模式中显示一些概要数据。
The following work ok:
scope :location_history, lambda { |id|
joins( INNER JOIN hotspots b ON locations.id = b.location_id INNER JOIN account ON b.mac = account.calledstationidclean )
.where(:id => id)
.select("count(locations.id) AS sessions_count, sum(account.acctoutputoctets) AS downloads, sum(account.acctinputoctets) AS uploads, count(distinct account.callingstationid) AS unique_user")
}
但我需要作一些计算,我可以说明如何这样做。
通常,在账户模式Im中,能够做这样的事情:
def self.session_time
Account.sum("acctsessiontime")
end
def self.average_session
self.session_time / Account.count
end
我怎么能做类似的事情,但在我的所在地模式中——并且只为特定地点“一米观察”展示信息? 我是否确实需要参加?