CakePHP 2.0可包含返回意外结果

CakePHP 2.0可包含返回意外结果,php,find,cakephp-2.0,containable,Php,Find,Cakephp 2.0,Containable,我有以下类和关联的数据库结构 class OrganisationAccount belongsTo Account belongsTo Organisation class Account hasOne User class Organisation belongsTo Account class User belongsTo Account 然后,我将使用CakePHP find和以下设置执行“全部查找”—— $OrganisationAcco

我有以下类和关联的数据库结构

class OrganisationAccount
    belongsTo Account
    belongsTo Organisation

class Account
    hasOne User

class Organisation
    belongsTo Account

class User
    belongsTo Account
然后,我将使用CakePHP find和以下设置执行“全部查找”——

$OrganisationAccount->Behaviors->load('Containable');
$records = $OrganisationAccount->find(
    'all',[
        'fields'=>[
            $OrganisationAccount->name.'.status',
            'Account.email_address',
            'Account.last_login',
        ],
        'conditions'=>[
            $OrganisationAccount->name.'.organisation_id'=>57
        ],
        'contain'=>[
            'Account'=>[
                'User'
            ]
        ]
    ]
);
现在,如果我使用上述方法执行查找,我会得到以下结果-

Array
(
    [0] => Array
        (
            [OrganisationAccount] => Array
                (
                    [status] => REGISTERED
                )

            [Account] => Array
                (
                    [email_address] => pdatar@checkvault.com.au
                    [last_login] => 2019-01-13 20:13:18
                    [id] => 44
                    [User] => Array
                        (
                            [id] => 32
                            [uuid] => 5c3814fc-2868-423f-9242-45b4cbdd56cb
                            [created] => 2019-01-11 04:01:00
                            [modified] => 2019-01-11 04:01:00
                            [account_id] => 44
                            [first_name] => John
                            [last_name] => Individual
                            [gender] => Not specified
                            [date_of_birth] => 
                            [display_picture] => 
                            [mobile] => 
                            [full_name] => John Individual
                        )

                )

        )

)
Array
(
    [0] => Array
        (
            [Account] => Array
                (
                    [email_address] => pdatar@checkvault.com.au
                    [last_login] => 2019-01-13 20:13:18
                    [id] => 44
                    [Account] => Array
                        (
                            [email_address] => pdatar@checkvault.com.au
                            [last_login] => 2019-01-13 20:13:18
                            [id] => 44
                            [User] => Array
                                (
                                    [id] => 32
                                    [uuid] => 5c3814fc-2868-423f-9242-45b4cbdd56cb
                                    [created] => 2019-01-11 04:01:00
                                    [modified] => 2019-01-11 04:01:00
                                    [account_id] => 44
                                    [first_name] => John
                                    [last_name] => Individual
                                    [gender] => Not specified
                                    [date_of_birth] => 
                                    [display_picture] => 
                                    [mobile] => 
                                    [full_name] => John Individual
                                )

                        )

                )

            [OrganisationAccount] => Array
                (
                    [status] => REGISTERED
                )

        )

)
这正是我所期待的

但如果我将Account字段放在find中fields数组中OrganizationAccount字段的上方

$OrganisationAccount->Behaviors->load('Containable');
$records = $OrganisationAccount->find(
    'all',[
        'fields'=>[
            'Account.email_address',
            'Account.last_login',
            $OrganisationAccount->name.'.status'
        ],
        'conditions'=>[
            $OrganisationAccount->name.'.organisation_id'=>57
        ],
        'contain'=>[
            'Account'=>[
                'User'
            ]
        ]
    ]
);
我得到以下结果-

Array
(
    [0] => Array
        (
            [OrganisationAccount] => Array
                (
                    [status] => REGISTERED
                )

            [Account] => Array
                (
                    [email_address] => pdatar@checkvault.com.au
                    [last_login] => 2019-01-13 20:13:18
                    [id] => 44
                    [User] => Array
                        (
                            [id] => 32
                            [uuid] => 5c3814fc-2868-423f-9242-45b4cbdd56cb
                            [created] => 2019-01-11 04:01:00
                            [modified] => 2019-01-11 04:01:00
                            [account_id] => 44
                            [first_name] => John
                            [last_name] => Individual
                            [gender] => Not specified
                            [date_of_birth] => 
                            [display_picture] => 
                            [mobile] => 
                            [full_name] => John Individual
                        )

                )

        )

)
Array
(
    [0] => Array
        (
            [Account] => Array
                (
                    [email_address] => pdatar@checkvault.com.au
                    [last_login] => 2019-01-13 20:13:18
                    [id] => 44
                    [Account] => Array
                        (
                            [email_address] => pdatar@checkvault.com.au
                            [last_login] => 2019-01-13 20:13:18
                            [id] => 44
                            [User] => Array
                                (
                                    [id] => 32
                                    [uuid] => 5c3814fc-2868-423f-9242-45b4cbdd56cb
                                    [created] => 2019-01-11 04:01:00
                                    [modified] => 2019-01-11 04:01:00
                                    [account_id] => 44
                                    [first_name] => John
                                    [last_name] => Individual
                                    [gender] => Not specified
                                    [date_of_birth] => 
                                    [display_picture] => 
                                    [mobile] => 
                                    [full_name] => John Individual
                                )

                        )

                )

            [OrganisationAccount] => Array
                (
                    [status] => REGISTERED
                )

        )

)
如您所见,记录在帐户索引中有一个帐户索引,这与之前的结果不同,即使字段数组包含相同的配置

查找数组是自动生成的


这是CakePHP的一个bug还是我做了一些不正确的事情?如果您在
组织
账户
之间有多对多关系
组织账户
,则
组织属于账户
会把
多对多账户
搞砸