I have simple relational Product - ProductCategories - Categories
class Product extends \Phalcon\Mvc\Model
{
public $id;
public $sku;
public $name;
public function initialize()
{
$this->hasManyToMany('id', 'Common\Models\ProductCategories', 'product_id', 'category_id', 'Common\Models\Categories', 'id', array('alias' => 'ProductCategories'));
}
}
class ProductCategories extends \Phalcon\Mvc\Model
{
public $id;
public $product_id;
public $category_id;
public function initialize()
{
$this->belongsTo('product_id', 'Common\Models\Product', 'id', array('alias' => 'Product'));
$this->belongsTo('category_id', 'Common\Models\Categories', 'id', array('alias' => 'Categories'));
}
}
class Categories extends \Phalcon\Mvc\Model
{
public $id;
public $section;
public $name;
public function initialize()
{
$this->hasManyToMany('id', 'Common\Models\ProductCategories', 'category_id', 'product_id', 'Common\Models\Product', 'id', array('alias' => 'ProductCategories'));
}
}
When I try to delete the related categories in product, ORM delete records from ProductCategories (that's ok) and delete categories from Categories (not ok).
$model = Product::findFirst($id);
$model->ProductCategories->delete()
I just need to delete ProductCategories through relationals, is that possible? Like this:
$productCategories = ProductCategories::find("product_id = '$id'");
$productCategories->delete();