3

必要なものだけにデータを制限するために、contains を使用すると奇妙なエラーが発生します。ここに私の内容があります

$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 が 2 つのエラーをスローすることです。

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]

問題は次の行に関係していると思います(含む: レビュー -> ユーザー):

'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 に答える