php - Cakephp 3 How to access deep contain associations in where clause? -


i have issue cakephp 3.3 in not know how access linked data using contain in clause.

here request :

$cables = tableregistry::get('cable_schedule');      $cablemark = 'test1';     $equipement = 'test2';     $compartment = 'test3';     $system = 'test4';      $query = $cables->find('all')->contain(['cabletype', 'contract', 'equipementsource' => ['compartment', 'system'], 'equipementdest' => ['compartment', 'system']])         ->where(['equipementsource.description like' => '%'.$equipement.'%'])         ->orwhere(['equipementdest.description like' => '%'.$equipement.'%'])         ->andwhere(['cable_mark like' => '%'.$cablemark.'%'])         ->andwhere(['equipementsource.compartment.description like' => '%'.$compartment.'%'])         ->orwhere(['equipementdest.compartment.description like' => '%'.$compartment.'%'])         ->andwhere(['equipementsource.system.description like' => '%'.$system.'%'])         ->orwhere(['equipementdest.system.description like' => '%'.$system.'%']);      $this->set('cables', $query); 

the error :

sqlstate[42s22]: column not found: 1054 unknown column 'equipementdest.system.description' in 'where clause'

you need use mathcing() method. see cakephp manual http://book.cakephp.org/3.0/en/orm/query-builder.html#filtering-by-associated-data

for example, if have table articles , has many tags, filter results this:

$query = $articles->find(); $query->matching('tags', function ($q) {     return $q->where(['tags.name' => 'cakephp']); }); 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -