From d49a8784e6d26a4cd9628b8d03cbada07e29046e Mon Sep 17 00:00:00 2001 From: Brandon Shipley Date: Mon, 29 Sep 2025 23:40:16 -0700 Subject: [PATCH] primary photo on products table --- src/Model/Table/ProductsTable.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Model/Table/ProductsTable.php b/src/Model/Table/ProductsTable.php index 38d53f9..44077b9 100644 --- a/src/Model/Table/ProductsTable.php +++ b/src/Model/Table/ProductsTable.php @@ -83,6 +83,20 @@ class ProductsTable extends Table 'cascadeCallbacks' => true, ]); + $this->hasMany('ProductPhotos', [ + 'foreignKey' => 'product_id', + 'className' => 'CakeProducts.ProductPhotos', + 'dependent' => true, + 'cascadeCallbacks' => true, + ]); + + $this->hasOne('PrimaryProductPhotos', [ + 'foreignKey' => 'product_id', + 'conditions' => ['PrimaryProductPhotos.primary_photo' => true], + 'className' => 'CakeProducts.ProductPhotos', + 'dependent' => true, + ]); + $this->getSchema()->setColumnType('product_type_id', EnumType::from(ProductProductTypeId::class)); $this->addBehavior('Muffin/Trash.Trash');