Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql CakePHP hasOne关联为不存在的记录返回空字段数组_Mysql_Cakephp_Model Associations_Cakephp 2.5 - Fatal编程技术网

Mysql CakePHP hasOne关联为不存在的记录返回空字段数组

Mysql CakePHP hasOne关联为不存在的记录返回空字段数组,mysql,cakephp,model-associations,cakephp-2.5,Mysql,Cakephp,Model Associations,Cakephp 2.5,具有用户和用户配置文件模型。用户模型与UserProfile只有一个关联。UserProfile mysql表为空。当我执行$this->User->find('all',array('contain'=>array('UserProfile'))而不是空的UserProfile数组时,正如您所期望的那样,我会得到一个填充了与架构对应的空字段的数组: Array ( [0] => Array ( [User] => Array

具有用户和用户配置文件模型。用户模型与UserProfile只有一个关联。UserProfile mysql表为空。当我执行$this->User->find('all',array('contain'=>array('UserProfile'))而不是空的UserProfile数组时,正如您所期望的那样,我会得到一个填充了与架构对应的空字段的数组:

Array ( [0] => Array ( [User] => Array ( [id] => 1 [firstname] => Joe [surname] => Bloggs [email] => katie.barnes@scotlandsdna.com [password] => $2a$10$re4r7AXWQcXgkKcabUqmtO6j.7p2bA1t2SLeG93eVsiDPBgGaeXRS [enabled] => 1 [user_group_id] => 1 [created] => 2014-06-26 15:01:38 [modified] => 2014-06-26 15:01:38 ) [UserProfile] => Array ( [id] => [job_title] => [user_id] => [enabled] => [created] => [modified] => ) ) 排列 ( [0]=>阵列 ( [用户]=>阵列 ( [id]=>1 [名字]=>乔 [姓氏]=>Bloggs [电子邮件]=>凯蒂。barnes@scotlandsdna.com [密码]=>2a$10$RE4R7AXWQCXGKCABQMTO6J.7P2BA1T2SLEG93EVSIDPBGAEXRS [已启用]=>1 [用户组id]=>1 [创建]=>2014-06-26 15:01:38 [修改]=>2014-06-26 15:01:38 ) [UserProfile]=>数组 ( [id]=> [职位名称]=> [用户id]=> [已启用]=> [已创建]=> [修改]=> ) )
有人看到并知道如何修复它吗?!

这是正确的行为,因为
hasOne
关联不是可选的。如果要将其设置为可选的,请将其更改为
hasMany
,并且只创建一条记录

Cake正在执行从
User
UserProfile
LEFT JOIN
,查询结果为缺少的记录生成
NULL
值。这与在Cake之外的编辑器中执行SQL时得到的结果相同