我正在使用DataMapper ORM,我有以下表格:
channel_providers
==================
id(pk)
name
channels
=========
id(pk)
channel_provider_id(fk)
name
sales_records
==============
id(pk)
channel_id(fk)
customer_name
salesman_name
amount
我想做的是,显示sales_records表中的所有行,包括渠道提供商名称和渠道名称,但按channel_providers表中的名称列分组。
目前,我有以下代码:
$sales_records=new Sales_record();
$sales_records->get();
foreach($sales_records as $sales_record){
$sales_record->channel->get();
$sales_record->channel->channel_provider->get();
//now I can write codes to to echo all data, but the problem is that $sales_records is not grouped by the channel_providers.name column
}
来自本页中的group_by示例:http: //datamapper.wanwizard.eu/pages/get.html
我知道我可以group_by
在对象关联的表中存在的列上使用函数。但是在我的情况下,我想使用group_by的列不在它自己的表中,怎么办?
非常感谢大家。