2012-12-08 23 views
3

当我使用包含限制我的数据只有我需要时,我有一个奇怪的错误。这里是我的包含CakePHP 2.0怪异array_merge使用时包含的错误

$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] 

我认为这个问题已经做了以下行(包含:回顾 - >用户):

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

如果我删除了一切正常,但是我又不想要所有来自用户的数据,特别是不是密码,所以我必须限制它。

我的Contain有什么问题?错误提示我应该在某处使用数组,但我不知道在哪里。

编辑添加的查询结果

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] => [email protected] 
          [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] => [email protected] 
          [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] => 
           ) 

         ) 

       ) 

     ) 

) 
+0

不知道这是你的问题,但是,我不认为你可以使用任何条件,如订单和限制。这些应该在你的'find()'语句中。只使用条件和字段。 –

+0

您实际上可以在包含中使用订单和限制。它的工作原理,Cakebook中实际使用了一个包含数组的命令: http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html 所以我怀疑是问题,我正在使用read()而不是find()。但是,这也不应该导致问题.... – Dakuipje

+0

好吧,我确实看到订单是在那里,但我没有看到限制,http://api20.cakephp.org/view_source/containable-behavior#line-302行302 - 314 –

回答

1

解决了这个问题,我在包含了一个错误。愚蠢的一个。

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

本来应该是:

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