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を使用したい列はそれ自体のテーブルにありませんが、これはどのように行うことができますか?
みなさん、ありがとうございました。