2

I tyed get with the method $this>model->find() an array with ids of my model that have this form:

Array ( [0] => 2,  [1] => 3)  (value are the IDs)

and I try $this->model->find('list') I thought that would work too but for some strange reason I have done:

$this->model->find('list',array('recursive' => -1  ,'fields' => array('model.type_id'),'conditions'=>$cond));

and the query result is:

SELECT `model`.`round_id`, `model`.`type_id` FROM `database`.`model` AS `X` WHERE `X`.`Round_id` = '1'

If I make this query to the database returns two values ​​but cakephp returns only one:

Array ( [1] => 2 )

i do not know that may be going

4

1 に答える 1

3

私は使うだろう

$ids = $this->Model->find('list', array('fields' => array('id')));

0 ベースの整数キーが本当に必要な場合でも、次のことができます。

$ids = array_values($ids);

しかし、それは必要ではありません。

アップデート:

質問が更新された後、質問自体の全体的な意味が変更されました。

id のみを指定すると、キーと値の両方に ID が入力されます。round_id'fields' => array('round_id', 'type_id')でキーを埋め、type_id で find(list) の値を埋めます。

find(list) は常にリスト (キー + 値行) を返します。使用したくない場合は、find(all) を使用します。

于 2013-01-25T10:18:31.827 に答える