Codeigniter/Datamapper を使用するアプリケーションがあります。Doctors 用のテーブルと Specialties 用のテーブルがあり、モデルは多対多の関係を持つように設定されています。
専門分野別に医師を照会しようとすると、すべての医師を照会するだけになることに気付きました。誰かが以前にこの問題を抱えていましたか? 私が使用しているコードは次のとおりです。
$s = new Specialty();
$s->where('id',$id)->get(); //thought maybe get_by_id($id) was causing the issue, it wasnt...
$this->out['query'] = $s->doctor->order_by('last_name','asc')->get_sql();
$docs = $s->doctor->order_by('id')->get_iterated();
$this->out['query'] は、次の SQL クエリで応答します。
"SELECT * FROM (`doctors`) ORDER BY `doctors`.`last_name` asc"
もう 1 つの奇妙な点は、結果が last_name の順序で返されないことですが、配列が json_encode 関数に渡される方法に何かがあると想定しています。