はい、適切なモデルメソッドを適切に呼び出す必要があります。また、保存するために渡す配列に情報が正しく格納されていることを確認する必要があります。つまり、レコードを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);
私はあなたがあなたの質問を明確にする必要があるとしていると思います。 – Dave
申し訳ありませんが、十分なコードがありません。なんでしょう? 2回$ this-> model? – craphunter
@Dave:おそらく、テーブルにデータを挿入するときに、 'id'を持っています。このidを別の列の値に設定したいとします。例えば、' id' = 10、 'title' = 'Post'、 'text' = 'HelloWorld'、 'link' = 10 – mrdaliri