3

使用包含将我的数据限制为我需要的数据时,我遇到了一个奇怪的错误。这是我的包含

$this->Movie->contain(array(
        'Review' => array(
            'fields' => array('id', 'title', 'spoilers', 'body', 'created'),
            'User' => array(
                'fields' => array('id', 'username'),
                'Profile' => array('fields' => array('id', 'image_thumb_small'))
            ),
            'order' => 'Review.created DESC',
            'limit' => 2,
        ),
        'Movieupdates' => array(
            'User' => array('Profile' => array('fields' => 'image_thumb_small')),
            'order' => 'Movieupdates.created DESC',
            'limit' => 2
        ),
        'Actor' => array(
            'fields' => array('name', 'slug', 'image_thumb'),
        ),
        'Genre' => array(
            'fields' => array('name', 'id'),
        )
    ));

问题是 Cakephp 向我抛出了两个错误:

Warning (2): array_merge() [function.array-merge]: Argument #1 is not an array [CORE\Cake\Model\Behavior\ContainableBehavior.php, line 400]

Warning (2): array_unique() expects parameter 1 to be array, null given [CORE\Cake\Model\Behavior\ContainableBehavior.php, line 400]

我认为问题与以下行有关(包含:Review -> User):

'fields' => array('id', 'username'),

如果我删除一切都很好,但我又不想从用户那里得到所有数据,尤其是密码,所以我必须限制它。

我的包含有什么问题?该错误表明我应该在某处使用数组,但我不知道在哪里。

编辑添加的查询结果

Array
(
    [Movie] => Array
        (
            [id] => 27
            [user_id] => 
            [title] => The Amazing Spider-Man
            [slug] => The_Amazing_Spider_Man_2012
            [year] => 2012
            [summary] => Peter Parker finds a clue that might help him understand why his parents disappeared when he was young. 
            [poster] => /files/movies/53cb8be658a2e04a21909e288cdcb8.jpg
            [poster_thumb] => /files/movies/53cb8be658a2e04a21909e288cdcb8_resized_101x150.jpg
            [backdrop] => /files/movies/backdrop/amazing_spider_man.jpg
            [rating] => 7.4285714285715
            [like_count] => 5
            [review_count] => 7
            [see_count] => 7
            [rating_count] => 14
        )

    [Movieupdates] => Array
        (
            [0] => Array
                (
                    [id] => 20
                    [user_id] => 4
                    [movie_id] => 27
                    [type] => 4
                    [info] => 26
                    [created] => 2012-12-08 11:06:18
                    [User] => Array
                        (
                            [id] => 4
                            [username] => Ceriksen
                            [email] => skdji@gmail.com
                            [password] => ---
                            [validation_code] => 082b7735cfb3a3d5c74547d702bd97f9af517870
                            [group_id] => 3
                            [created] => 2012-11-27 11:23:57
                            [modified] => 2012-11-27 11:23:57
                            [Profile] => Array
                                (
                                    [id] => 5
                                    [user_id] => 4
                                    [image] => /files/profiles/771a98602dc7849b2d004952f1f35f.jpg
                                    [image_thumb] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_130x130-2.jpg
                                    [image_thumb_medium] => 
                                    [image_thumb_small] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_30x30.jpg
                                    [name] => 
                                    [last_name] => 
                                    [bio] => 
                                    [country] => 
                                    [city] => 
                                )

                        )

                )

            [1] => Array
                (
                    [id] => 19
                    [user_id] => 4
                    [movie_id] => 27
                    [type] => 3
                    [info] => 10
                    [created] => 2012-12-08 11:06:08
                    [User] => Array
                        (
                            [id] => 4
                            [username] => Ceriksen
                            [email] => skdji@gmail.com
                            [password] => ---
                            [validation_code] => 082b7735cfb3a3d5c74547d702bd97f9af517870
                            [group_id] => 3
                            [created] => 2012-11-27 11:23:57
                            [modified] => 2012-11-27 11:23:57
                            [Profile] => Array
                                (
                                    [id] => 5
                                    [user_id] => 4
                                    [image] => /files/profiles/771a98602dc7849b2d004952f1f35f.jpg
                                    [image_thumb] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_130x130-2.jpg
                                    [image_thumb_medium] => 
                                    [image_thumb_small] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_30x30.jpg
                                    [name] => 
                                    [last_name] => 
                                    [bio] => 
                                    [country] => 
                                    [city] => 
                                )

                        )

                )

        )

    [Genre] => Array
        (
            [0] => Array
                (
                    [name] => Action
                    [id] => 11
                    [MoviesGenre] => Array
                        (
                            [id] => 56
                            [movie_id] => 27
                            [genre_id] => 11
                        )

                )

            [1] => Array
                (
                    [name] => Adventure
                    [id] => 12
                    [MoviesGenre] => Array
                        (
                            [id] => 57
                            [movie_id] => 27
                            [genre_id] => 12
                        )

                )

            [2] => Array
                (
                    [name] => Fantasy
                    [id] => 18
                    [MoviesGenre] => Array
                        (
                            [id] => 58
                            [movie_id] => 27
                            [genre_id] => 18
                        )

                )

        )

    [Actor] => Array
        (
            [0] => Array
                (
                    [name] => Emma
                    [slug] => Emma_Stone
                    [image_thumb] => /files/actors/d59efc7614151acb7ea5d08da47112_resized_30x30.jpg
                    [MoviesActor] => Array
                        (
                            [id] => 1
                            [movie_id] => 27
                            [actor_id] => 8
                        )

                )

            [1] => Array
                (
                    [name] => Andrew
                    [slug] => Andrew_Garfield
                    [image_thumb] => /files/actors/0a9354d741328f4cf3e2954641e4eb_resized_25x30.jpg
                    [MoviesActor] => Array
                        (
                            [id] => 2
                            [movie_id] => 27
                            [actor_id] => 9
                        )

                )

            [2] => Array
                (
                    [name] => Martin
                    [slug] => Martin_Sheen
                    [image_thumb] => /files/actors/2383fc87054b2e8b4249fc7e3ffba5_resized_30x27.jpg
                    [MoviesActor] => Array
                        (
                            [id] => 3
                            [movie_id] => 27
                            [actor_id] => 10
                        )

                )

        )

    [Review] => Array
        (
            [0] => Array
                (
                    [id] => 26
                    [title] => W00t
                    [spoilers] => 0
                    [created] => 2012-12-08 11:06:18
                    [user_id] => 4
                    [MoviesReview] => Array
                        (
                            [id] => 25
                            [movie_id] => 27
                            [review_id] => 26
                        )

                    [User] => Array
                        (
                            [id] => 4
                            [username] => Ceriksen
                            [Profile] => Array
                                (
                                    [id] => 5
                                    [user_id] => 4
                                    [image] => /files/profiles/771a98602dc7849b2d004952f1f35f.jpg
                                    [image_thumb] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_130x130-2.jpg
                                    [image_thumb_medium] => 
                                    [image_thumb_small] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_30x30.jpg
                                    [name] => 
                                    [last_name] => 
                                    [bio] => 
                                    [country] => 
                                    [city] => 
                                )

                        )

                )

            [1] => Array
                (
                    [id] => 25
                    [title] => Testing the update
                    [spoilers] => 1
                    [created] => 2012-12-08 11:04:44
                    [user_id] => 4
                    [MoviesReview] => Array
                        (
                            [id] => 24
                            [movie_id] => 27
                            [review_id] => 25
                        )

                    [User] => Array
                        (
                            [id] => 4
                            [username] => Ceriksen
                            [Profile] => Array
                                (
                                    [id] => 5
                                    [user_id] => 4
                                    [image] => /files/profiles/771a98602dc7849b2d004952f1f35f.jpg
                                    [image_thumb] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_130x130-2.jpg
                                    [image_thumb_medium] => 
                                    [image_thumb_small] => /files/profiles/771a98602dc7849b2d004952f1f35f_resized_30x30.jpg
                                    [name] => 
                                    [last_name] => 
                                    [bio] => 
                                    [country] => 
                                    [city] => 
                                )

                        )

                )

        )

)
4

1 回答 1

1

解决了,我的容器有错误。愚蠢的一个。

'User' => array('Profile' => array('fields' => 'image_thumb_small')),

本来应该:

'User' => array('Profile' => array('fields' => array('image_thumb_small'))),
于 2012-12-08T14:33:28.710 回答