0
我有兩個型號 - Cars
和CarOptions
CakePHP的3個不節能hasOne協會
Cars
hasOne CarOptions
如果用戶要編輯汽車 - 他們還可以設置一些CarOptions和保存
相關的一切到Cars
保存就好了,但CarOptions
不保存。如果我要調試Car
對象只保存前 - 我看到下面的
Car: {
"id": 3,
"name": "Ford Mustang",
"description": "some description",
"city": "San Francisco",
"state": "California",
"country": "USA",
"created": "2015-08-14T12:20:14-0500",
"CarOptions": {
"manual_transmission": "N"
}
}
我的代碼保存爲如下
$car = $this->Cars->findByName('Ford Mustang')->first();
$car = $this->Cars->patchEntity($car, $this->request->data);
$carOptions = $this->Cars->CarOptions->newEntity();
$carOptions->manual_transmission = 'N';
$car->CarOptions = $carOptions;
$this->Cars->save($car);
但是沒有創建或編輯的CarOptions記錄。我錯過了什麼?
謝謝 - 這工作。硬編碼僅用於測試目的 – ChicagoSky