I’ve 3 tables:
project, amenities and project_amenities.
I add project form only, i want to add new amenities, which first added to amenities table and then project_amenities table.
So I defined these relations:
Project hasMany Amenities
Amenity belongsTo Project
I declared in projects_controller:
var $uses = array('Amenity');
This gives error for my add action here
if (!empty($this->data)){
$this->Project->create();
as
Notice (8): Undefined property: ProjectsController::$Project
[APP\controllers\projects_controller.php, line 60]
edit
Also, I cannot do:
$this->Amenity->create();
$insertData = array('name' => $this->data['Project']['Amenity'][$i]['name']);
$this->Amenity->save($insertData);
I would like to suggest you to use
$this->loadModel('ModelName');in the function where you needed. Then you can use the model as belowBy using
$usesarray it make available to entire controller. Which will affect your performance.