CakePHP 3 associates between two tables -


i trying create associations between 2 models ( servers , application_endpoints) tables in cakephp 3. achieve data application_endpoints table servers model. in view can access data.

server can have multiple vips , endpoints in application_endpoints table , using hasmany association. in serverstable.php added below code:

$this->hasmany('applicationendpoints', [             'foreignkey' => 'server_id',             'dependent' => true         ]); 

so when browse server view page , click on debug kit inside variable tab, dont see joins. see list of servers in array, each server in array doesnt show relationships application_endpoints table.

please comment , let me know if not clear, linking sqlfiddle mysql schema.

update 1

i tried code in serverstable.php:

$this->belongsto('applicationendpoints', [             'bindingkey' => 'server_id',             'jointype' => 'inner',         ]); 

so hasmay right way make association between 2 models.

    $this->hasmany('applicationendpoints', [         'foreignkey' => 'server_id',         'dependent' => true     ]); 

i had add code in controller of server make work below code:

    // view method     $query = $this->servers->get($id, [         'contain' => ['applicationendpoints']     ]);     $this->set('data', $query); 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -