Да, но вам нужно сделать правильные вызовы для правильных методов модели. Вам также необходимо убедиться, что вы правильно храните информацию в массиве, который вы передаете для сохранения. Допустим, вы добавляете запись в таблицу places
. Допустим, ваша схема выглядит следующим образом:
CREATE TABLE 'places' (
`id` CHAR(36) NOT NULL,
`reference_id` CHAR(36) NULL,
`name` VARCHAR(50) NOT NULL,
PRIMARY KEY (`id`)
);
Тогда у вас есть следующее:
$data['Place']['name'] = 'New York';
// create the first record to get the PK ID that will
// be used in the reference_id of the next record
$this->Place->create();
$this->Place->save($data);
// set the reference ID to the ID of the previously saved record
$data['Place']['reference_id'] = $this->Place->id;
// create the next record recording the previous ID as
// the reference_id
$this->Place->create();
$this->Place->save($data);