目前我正在使用 CakePHP 连接到 SQL Server 的应用程序。
在我的 SQL 数据库上,我有多个模式(而不是多个数据库 - 良好做法)。例如,我如何加入多个模式以在一个响应中获取所有数据?
目前我正在使用 CakePHP 连接到 SQL Server 的应用程序。
在我的 SQL 数据库上,我有多个模式(而不是多个数据库 - 良好做法)。例如,我如何加入多个模式以在一个响应中获取所有数据?
Try this -
$books = $this->Books->find('all',['fields' => ['id' => 'Books.id', 'name' => 'Books.name''category_id' => 'bc.category_id','category' => 'ac.category']])
->join([
'bc' => [
'table' => 'Book_categories',
'type' => 'INNER',
'conditions' => 'bc.book_id = Books.id'
],
'ac' => [
'table' => 'All_categories',
'type' => 'INNER',
'conditions' => 'bc.category_id = ac.id'
]
]);
请注意,字段名称被提及为关联数组('alias' => 'column ref'),您可以仅提及列名,但这将获取不同数组中不同表的结果(例如,[ac] 数组将包含[类别] => 'cat_name' )