別のモデルの拡張であるさまざまなモデルがあります。
classes (SubModel1, SubModel2, ..,6) extends -> HighModel extends -> Appmodel
各サブモデルにデータを保存するたびに、HighModel で関数を呼び出して、保存したばかりのサブモデルの ID を保存します。
5 つのサブモデルで完全に動作しますが、1 つの id は常に:
($shouldBeThisId - 1)
追加機能と編集機能の両方で.... o_O
これが私の追加機能です:
public function add() {
if ($this->request->is('post')) {
$this->M18Tab->create();
if ($this->M18Tab->save($this->request->data)) {
$data = $this->M18Tab->findById($this->M18Tab->id); //<---problem's here
if($this->M18Tab->M18Model->saveVersion($data)){
$this->Session->setFlash(__('The m18 tab has been saved'));
$this->redirect(array('action' => 'view', $this->M18Tab->id));
} else {
$this->Session->setFlash(__('Error with versioning system'));
}
} else {
$this->Session->setFlash(__('The m18 tab could not be saved. Please, try again.'));
}
}
//view variables
}
わかった。保存した後、「保存したばかりのデータ」を呼び出してに渡します$this->SubModel->HighModel->saveVersion($data)
。奇妙なことに、ID を強制的に検索しようとすると、次のようになります。
$data = $this->M18Tab->findById(33);
挿入されたばかりの ID :0 の前の ID も検索されます。
これは何が原因でしょうか?コードは6つのモデルすべてで同じですが、この問題が発生したのは1つだけです..