id
に複数のレコードを保存するためのリレーショナル データを含む配列要素を配列内に挿入しようとしていますCakePHP
。
配列は次のように表示されます。
[Venue] => Array (
[0] => Array (
[name] => Great mansion
[where] => New York
)
[1] => Array (
[name] => Diamond palace
[where] => London
)
[2] => Array (
[name] => Palazzo Falcone
[where] => Bologna
)
)
architect_id
配列のすべての要素にを追加したいので、次のようにします。
[Venue] => Array (
[0] => Array (
[name] => Great mansion
[where] => New York
[architect_id] => 33
)
[1] => Array (
[name] => Diamond palace
[where] => London
[architect_id] => 33
)
[2] => Array (
[name] => Palazzo Falcone
[where] => Bologna
[architect_id] => 33
)
)
私が書いたものが最適化されているかどうか、または改善できるかどうかはわかりません。
$tot = count($this->request->data['Venue']);
for ($i = 0; $i < $tot; $i ++) {
$this->request->data['Venue'][$i]['architect_id'] = $this->Architect->id;
}
$this->Venue->saveAll($this->request->data['Venue']);
コードは機能しますが、これは良い方法ですか?