CakePHP 3 Find All Contain NULL data, displays nothing? -


update

this join sql after selects,

from users users  left join userinfos userinfos on userinfos.id = (users.userinfo_id)  inner join offices offices on offices.id = (userinfos.office_id) 

ok, have database (mysql) setup cakephp 3 users table has extended information held within table.

this other table extended office / address information set null default, want include in 'contain' call dose not return user data when empty?

so use currently,

  $userstable->find('all')              ->contain(['userinfos','userinfos.offices'])              ->toarray(); 

but, offices (office_id field in table usersinfos) not set, still want return users if don't have office set.

so have tried,

  $userstable->find('all')              ->contain([                   'userinfos',                   'userinfos.offices'               ])              ->where(['userinfos.office_id is' => null])              ->toarray(); 

also,

  $userstable->find('all')              ->contain([                   'userinfos',                   'userinfos.offices' =>                            function($q) {                              return $q->where(['userinfos.office_id is' => null]);                           }               ])             ->toarray(); 

the $userstable var set to

   $userstable = tableregistry::get('users'); 

if remove userinfos.offices contain condition, returns current users. however, how can call in data/information have access office information, e.g location name if set?

*i may not have explain myself clearly, please let me know if there can explain better, thanks.

in cakephp3.x in default when bake model join table set inner join. need modify model associations. need set association left join.

in case if @ 'userinfostable' in src/model/userinfostable make sure 'left join' ing 'user' table or can remove 'jointype' because in default cakephp sets contain 'left join'

class userinfostable extends table {     public function initialize(array $config)     {        $this->belongsto('userinfos', [             'foreignkey' => 'office_id',             'jointype' => 'left'       ]);    } } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -