Thanks for the link.

I did modelize my HABTM table, now I have a "ModelsPart" model, and it  
has a $belongsTo to Part and Model.

Unfortunately, getting related parts when I'm using find() or  
findAll() in ModelsController doesnt work, but I can get related  
models from PartsController.

Any more ideas?

On May 20, 2008, at 3:27 PM, Matt Huggins wrote:

>
> You need to modelize your HABTM table.  Hopefully this link will help
> you out.
>
> http://cricava.com/blogs/index.php?blog=6&title=modelizing_habtm_join_tables_in_cakephp_&more=1&c=1&tb=1&pb=1
>
>
> On May 20, 3:04 am, Reza Muhammad <[EMAIL PROTECTED]> wrote:
>> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to