CakePHP模型查询返回数据格式 [英] CakePHP Model Query Return Data Formating

查看:104
本文介绍了CakePHP模型查询返回数据格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种使之成为蛋糕的方法,以便cake以相同的格式/结构返回所有数据库数据...目前,根据关系,它返回两种不同类型的格式.

I'm looking for a way to make it so cake returns all database data in the same format/structure... Currently it returns two different types of format depending on the relationship.

如果模型"B"与正在查询的当前模型"A"相关联,则将在其下方放置"B"的模型关联,如下面的[用户]中所示.我想要它,以便所有查询都使用该结构.

If a model 'B' is associated with the current model 'A' being queried it will then place model associations for 'B' underneath it as you can see in [User] below. I want it so that all queries use that structure.

示例: $ this-> find('all',.... 返回:

example: $this->find('all', .... returns:

Array
(
    [0] => Array
        (
            [UserGroup] => Array
                (
                    [id] => 53
                    [user_id] => 100003332014851
                    [media_id] => 
                    [name] => john
                    [description] => qwasdfad
                )


            [User] => Array
                (
                    [id] => 100003332014851
                    [session_id] => ssm2qbrotmm13ho1ipm8ii2492
                    [username] => 
                    [password] => -1
                    [Planner] => Array
                         (
                         )

                     [Purchase] => Array
                         (
                         )

                     [Listing] => Array
                         (
                         )
               )
       )

我希望它看起来像这样:

I want this to look like:

Array
(
    [0] => Array
        (
            [UserGroup] => Array
                (
                    [id] => 53
                    [user_id] => 100003332014851
                    [media_id] => 
                    [name] => john
                    [description] => qwasdfad
                    [User] => Array
                         (
                              [id] => 100003332014851
                              [session_id] => ssm2qbrotmm13ho1ipm8ii2492
                              [username] => 
                              [password] => -1
                              [Planner] => Array
                                   (
                                   )

                               [Purchase] => Array
                                   (
                                   )

                               [Listing] => Array
                                   (
                                   )
                            )
                     )
               )
       )

推荐答案

在这种情况下,您还可以将contains用作 UserGroup.User 来获得所需的结果

You can also use contain in this case along with find as UserGroup.User for your desired result

这篇关于CakePHP模型查询返回数据格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆