CakePHP Associations

  • Tannu4u
  • Proficient
  • Proficient
  • User avatar
  • Posts: 480
  • Loc: India

Post 3+ Months Ago

Hi All,

I have three tables A,B & C. The association is such that table A belongs to B & B belongs to C.

Now when i am running a find on table A, i need to fetch the associated records from table C as well. I have set the recursive parameter for table A to 1, but i am not getting the records fro table C.

Can anyone have any idea how to get this one working?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Tannu4u
  • Proficient
  • Proficient
  • User avatar
  • Posts: 480
  • Loc: India

Post 3+ Months Ago

Hi all,

This is the function that i am using to get this association in cakePHP

Code: [ Select ]
function unbindAndBind(){
        // unbind State model for entire request
        $this->City->unbindModel(array('belongsTo' =>array('State')), false);

        // unbind State->Country model for entire request
        $this->City->State->unbindModel(array('belongsTo' =>array('Country')), false);

        // rebind Site and Company models with custom condition for Company model forcing join
        $this->City->bindModel(array
                                    (
                                        'belongsTo' => array(
                                            'State' => array(),
                                            'Country' => array(
                                                                'foreignKey' => false,
                                                                'conditions' => array('State.country_id = Country.id')
                                                         )
                                        )
                                    ),
                                    false
        );
    }
  1. function unbindAndBind(){
  2.         // unbind State model for entire request
  3.         $this->City->unbindModel(array('belongsTo' =>array('State')), false);
  4.         // unbind State->Country model for entire request
  5.         $this->City->State->unbindModel(array('belongsTo' =>array('Country')), false);
  6.         // rebind Site and Company models with custom condition for Company model forcing join
  7.         $this->City->bindModel(array
  8.                                     (
  9.                                         'belongsTo' => array(
  10.                                             'State' => array(),
  11.                                             'Country' => array(
  12.                                                                 'foreignKey' => false,
  13.                                                                 'conditions' => array('State.country_id = Country.id')
  14.                                                          )
  15.                                         )
  16.                                     ),
  17.                                     false
  18.         );
  19.     }

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 86 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.