CakePHP 独自SQLを query() 関数で実行する場合の記述方法(Postgresql)

SQLコマンドを独自で作り、query()関数で取得する場合
通常と同じ形式でデータを取得するSQL文の書き方について

テーブル校正
Sections: id, name
Users: id, name,section_id

SQL



SQL = sprintf("
SELECT
s.name AS \"Section__name\"
, u.name AS \"User__name\"
FROM sections AS s
LEFT JOIN users AS u
ON s.id = u.section_id
ORDER BY 1
");

実行結果



$datas = $this->query( $SQL );
debug($datas);

Array
(
[0] => Array
(
[Section] => Array
(
[name] => ZZZ
)
[User] => Array
(
[name] => hoge
)
)
[2] => Array
(
[Section] => Array
(
[name] => AAA
)
[User] => Array
(
[name] => hogehoge
)
)