Hi guys.
I just tried to setup a HABTM relationship between "Model" and
"Parts". In my "Model" model. I already created tables called
'models', 'parts', and 'models_parts'.
Here's what I have in my models:
- model.php
class Model extends AppModel {
var $name = 'Model';
var $useTable = 'models';
var $validate = array(
'name' => array(
'rule' => VALID_NOT_EMPTY,
'required' => true,
'message' => 'Model name must only contains letters and
numbers'
)
);
//The Associations below have been created with all possible keys,
those that are not needed can be removed
var $hasAndBelongsToMany = array(
'Part' => array('className' => 'Part',
'joinTable' => 'models_parts',
'foreignKey' => 'model_id',
'associationForeignKey' => 'part_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
}
- part.php
class Part extends AppModel {
var $name = 'Part';
var $useTable = 'parts';
//The Associations below have been created with all possible keys,
those that are not needed can be removed
var $hasAndBelongsToMany = array(
'Model' => array('className' => 'Model',
'joinTable' => 'models_parts',
'foreignKey' => 'part_id',
'associationForeignKey' =>
'model_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
}
Now, the problem is, When I run find() from Parts Controller, I can
get the data from table models_parts (So, I can tell which parts
belongs to which models). However, I also want to be able to get data
from table models_parts when I run find() from Models Controller.
I have set both of these controllers to use recursive = 2 ($this->Part-
>recursive = 2, and $this->Model->recursive=2), yet it only works
from Parts, not the model.
Should I be creating a ModelPart model too?
Please help me out, thank you :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---