I have the following relationship between models:
class Product extends \Common\Models\ModelBase {
public $id;
public function initialize()
{
$this->hasMany('id', 'Common\Models\ProductProperties', 'product_id', array('alias' => 'ProductProperties'));
$this->hasManyToMany('id', 'Common\Models\ProductProperties', 'product_id', 'property_id', 'Common\Models\Properties', 'id', array(
'alias' => 'Properties',
'params' => ['order' => 'sort_id']
));
}
}
class ProductProperties extends \Phalcon\Mvc\Model {
public $id;
public $product_id;
public $property_id;
public function initialize()
{
$this->belongsTo('product_id', 'Common\Models\Product', 'id', array('alias' => 'Product', 'reusable' => true));
$this->belongsTo('property_id', 'Common\Models\Properties', 'id', array('alias' => 'Properties', 'reusable' => true));
}
}
class Properties extends \Common\Models\ModelBase {
public $id;
public function initialize()
{
$this->hasManyToMany('id', 'Common\Models\ProductProperties', 'property_id', 'product_id', 'Common\Models\Product', 'id', array('alias' => 'ProductProperties'));
$this->hasMany('id', 'Common\Models\PropertiesParams', 'property_id', array(
'alias' => 'Params',
'params' => ['order' => 'sort_id']
));
}
}
class PropertiesParams extends \Common\Models\ModelBase {
public $id;
public $property_id;
public function initialize()
{
$this->belongsTo('property_id', 'Common\Models\Properties', 'id', array('alias' => 'Properties', 'reusable' => true));
}
}
So, I have Product, Properties and Properties Params. For Product I can choose custom Properties. I need to have possibility to choose custom Property Params for Product. I need to create new table ProductPropertiesParams and whan kind of relation for this I need to use? I want to sometsing like this:
$product = Product::findFirst($id);
$product->Properties // properties for product
$product->Properties->Param // it's work's right now, but it's params for Properties
// I need:
$product->Properties->ProductParams
How to implement this?