是这样的:
$this->loadModel('IntAdmin');
$test = $this->IntAdmin->find('list', [
'contain' => ['Sales', 'Accounts'],
'conditions' => [
'IntAdmin.status' => 'submitted',
'IntAdmin.id IN' => [$picking_lists['picking_list']]
]
]);
pr($test);
exit;
在$picking_lists
中,我有:
Array
(
[picking_list] => Array
(
[0] => 10
[1] => 11
)
)
这是pr()
结果:
Cake'ORM'Query Object
(
[(help)] => This is a Query object, to get the results execute or iterate it.
[sql] => SELECT IntAdmin.id AS `IntAdmin__id` FROM int_admins IntAdmin INNER JOIN sales Sales ON Sales.id = (IntAdmin.sale_id) INNER JOIN accounts Accounts ON Accounts.id = (IntAdmin.account_id) WHERE (IntAdmin.status = :c0 AND IntAdmin.id in (:c1))
[params] => Array
(
[:c0] => Array
(
[value] => submitted
[type] => string
[placeholder] => c0
)
[:c1] => Array
(
[value] => Array
(
[0] => 10
[1] => 11
)
[type] => integer
[placeholder] => c1
)
)
[defaultTypes] => Array
(
[IntAdmin.id] => integer
[id] => integer
[IntAdmin.user_id] => integer
[user_id] => integer
[IntAdmin.username] => string
[username] => string
[IntAdmin.sale_id] => integer
[sale_id] => integer
[IntAdmin.account_id] => integer
[account_id] => integer
[IntAdmin.pl_number] => string
[pl_number] => string
[IntAdmin.receiving_date] => datetime
[receiving_date] => datetime
[IntAdmin.status] => string
[status] => string
)
[decorators] => 0
[executed] =>
[hydrate] => 1
[buffered] => 1
[formatters] => 1
[mapReducers] => 0
[contain] => Array
(
[Sales] => Array
(
)
[Accounts] => Array
(
)
)
[matching] => Array
(
)
[extraOptions] => Array
(
)
[repository] => App'Model'Table'IntAdminTable Object
(
[registryAlias] => IntAdmin
[table] => int_admins
[alias] => IntAdmin
[entityClass] => App'Model'Entity'IntAdmin
[associations] => Array
(
[0] => users
[1] => accounts
[2] => sales
)
[behaviors] => Array
(
)
[defaultConnection] => default
[connectionName] => default
)
)
我在这里找不到问题,但查询返回空结果。请帮助。
如果你需要更多的信息,请询问。
谢谢
使用toArray打印结果
$this->loadModel('IntAdmin');
$test = $this->IntAdmin->find('list', [
'contain' => ['Sales', 'Accounts'],
'conditions' => [
'IntAdmin.status' => 'submitted',
'IntAdmin.id IN' => [$picking_lists['picking_list']]
]
]);
pr($test->toArray());
exit;