Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Bind Model in cakephp

    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 360
    Comment on it

    In one of my project I have two table with simple relation

    Division (id, title) - hasMany Staff
    Staff (id, division_id, name, jobtitle)
    

    So. Now I need to get some info like: I need to get all Staff where birthday today, and get result like:

    Array (
       [0] => ["Division"] = Array ...
             => ["Staff"] = [0]
      [1] ...
    

    But I don't want (or cann't) rewrite model fore staff/division. So, What I must doing? Of cause I must to use this wonderful thing - bindModel ;-)

    Look

    $this->Division->bindModel(array("hasMany" => array ("Staff" => array (
    "conditions" => array ("MONTH (birthday) = " . $month, "DAY (birthday) = " . $day),
    "fields" => array ("Staff.id,Staff.name"),
    "order" => array("Staff.name" => "ASC")))));
    $staff = $this->Division->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: