Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Make Database Association on Selected Pages In Cakephp

    • 0
    • 1
    • 1
    • 2
    • 0
    • 0
    • 0
    • 0
    • 117
    Comment on it

    If you want to make Database Association on Selected Pages In Cakephp follow the below steps,

    Below code can set association where it require and you can also reduce unnecessary queries firing to database.

    1. Make function in your model and set your association type, for example
    class ModelName extends AppModel{
    function findByXYZ($arguments){
          $this->hasMany        =           array(
                                              'TableNameHere' => array(
                                                    'className' => 'classnamehere',
                                                    'foreignKey' => 'foreignKeyHere',
                                                    'limit' => '1',
                                                    'dependent' => true
                                               )
                                            );
    }
    }
    
    1. Now set this function before any table data selection:
    $this->ModelName->findByXYZ($params);
    $this->Model->find('all');
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: