cakephp - Cake PHP Model Associations - What am I doing wrong? -


no matter how many times read through documentation, @ examples cannot model "associate" another.

here example:

i have table called kits , table called grades (read books , authors).

kits looks (simplified):

  1. id (pk)
  2. grade_id (fk)
  3. name

grades looks likes this:

  1. id (pk)
  2. code

each kit have 1 grade. don't see issue naming conventions, follows prescribed in api.

--

i have controller called kitscontroller.php looks this:

class kitscontroller extends appcontroller {     public function index() {         //simple find limits 1 (for readability)         $pigs = $this->kit->find("all", array(              "limit" => 1         ));          $this->set("pigs", $pigs);     } } 

i have corresponding index.ctp file outputs variable $pigs (not production level variable name know).

--

i have model called kitmodel.php

class kit extends appmodel {     public $belongsto = "grade";//here confused } 

...and empty grade model placeholder

class grade extends appmodel {  } 

--

the problem:

when array prints out on page looks this.

array ( [0] => array (      [kit] => array (          [id] => 1          [grade_id] => 1          [name] => ferrari  )   )   ) 

from understanding when print out results should include grade information along kit information. every example have seen online. have tried different relationships (hasone, etc) no avail. have tried long form passing in array classname , foreign key if schema matches cakephp convention shouldn't have that.

what missing?

i have model called kitmodel.php

your model filename incorrect. should kit.php. if cakephp doesn't find model file named per convention uses appmodel instance model.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -