前提・実現したいこと
cakephp3でsaveをしたいのですが、孫アソシエーションが機能しません。
全体の動きとしては保存までは出来ている状態で、featuresの子であるfeature_paragrathsは問題なく保存されるのですがその更に下にいるfeature_productsが保存されずスルーされてしまいます。
https://qiita.com/zaramme/items/719f77480c5f0cde0ae1
こちらの記事を参考にしたのですが、上手く動いてくれない状況です。
以下のソースですとDBエラーが出てfeature_productsのfeature_idがないと言われます。
Error: SQLSTATE[HY000]: General error: 1364 Field 'feature_id' doesn't have a default value
原因は分かっているのですが、書き方がわからない為困っております。
該当のソースコード
$associated = ['FeatureParagraphs','FeatureParagraphs.FeatureProducts', 'FeatureProducts']; $featureEntity = $this->Features->patchEntity($featureEntity, $data, ['associated' => $associated]); if (!$this->Features->save($featureEntity)) { $this->Flash->error(__('失敗')); } else { $this->Flash->success(__('成功')); }
$featureEntity
patchEntityをした後の$featureEntityが以下になります。
$featureEntity └ title start_date end_date features_paragraths └ subtitle feature_products └ prosuct_id └ 1 2 3
テーブル情報
features
id | title | start_date | end_date |
---|---|---|---|
feature_paragraths
id | feature_id | subtitle |
---|---|---|
feature_products
id | feature_id | feature_paragrath_id | product_id |
---|---|---|---|
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/06/09 09:14
2020/06/15 09:52