I have a site develop in cakephp 2.0 I want to make a HABTM relation to the same model: A product can has more products.
I thinked to do in this mode into my model:
class Product extends AppModel {
public $name = 'Product';
public $useTable = 'products';
public $belongsTo = 'User';
public $actsAs = array('Containable');
public $hasAndBelongsToMany = array(
'Ingredient' => array(
'className' => 'Product',
'joinTable' => 'ingredients_products',
'foreignKey' => 'product_id',
'associationForeignKey' => 'ingredient_id',
'unique' => true
)
);
}
Is correct my relation? But have I to insert into my table products the field product_id and ingredient_id? And how can I save my data with a form? I know how to save data with HABTM but I never done an HABTM to the same table.