2014-06-16 25 views
-1

我有故事涉及到一個多對多的章節 我有一個StoryChapter模型。與cakephp訂購multidimentional數組全部查找

我有這樣的找到所有故事的結果是:

array(
(int) 0 => array(
    'Story' => array(
     'id' => '111', 
     'title' => 'First Story', 
     'question' => 'What do you want ?', 
     'description' => 'ezrsrfgq ergtqergq', 
     'date' => '2014-06-10', 
     'image' => '/uploads/stories/111.jpg', 
     'created' => '2014-06-10 07:51:35', 
     'modified' => '2014-06-13 12:45:43', 
     'created_by' => '1', 
     'original' => null, 
     'tags' => '' 
    ), 
    'StoryChapter' => array(
     (int) 0 => array(
      'id' => '110', 
      'story_id' => '111', 
      'chapter_id' => '81', 
      'chapter_title' => 'Second Chapter', 
      'created' => '2014-06-11 00:00:00' 
     ), 
     (int) 1 => array(
      'id' => '109', 
      'story_id' => '111', 
      'chapter_id' => '80', 
      'chapter_title' => 'First Chapter', 
      'created' => '2014-06-13 00:00:00' 
     ) 
    ), 
    'StoryUser' => array(), 
    'StoryGroup' => array(), 
    'Favorite' => array(), 
    'Tag' => array() 
), 
(int) 1 => array(
    'Story' => array(
     'id' => '112', 
     'title' => 'Second Story', 
     'question' => 'What do you want ?', 
     'description' => 'edghs rthsghsx ghs rhsgrhsrtgh', 
     'date' => '2014-06-13', 
     'image' => '/uploads/stories/112.jpg', 
     'created' => '2014-06-13 07:43:18', 
     'modified' => '2014-06-13 07:43:18', 
     'created_by' => '1', 
     'original' => null, 
     'tags' => '' 
    ), 
    'StoryChapter' => array(), 
    'StoryUser' => array(), 
    'StoryGroup' => array(), 
    'Favorite' => array(), 
    'Tag' => array() 
) 

我想查找功能命令只能由創建遞減的StoryChapter不影響發現故事的順序。

我希望你明白我的意思。

謝謝

+0

添加的hasMany排列順序解決了這個問題。 – AgRizzo

+0

我不想訂購故事,但只訂購屬於故事的故事分類器 – R4mirezZ

+0

您可以訂購多個字段/列。 – AgRizzo

回答

0

我在把一個`ORDER BY`在`find`方法故事模式

public $hasMany = array(
    'StoryChapter' => array(
     'className' => 'StoryChapter', 
     'foreignKey' => 'story_id', 
     'dependent' => false, 
     'conditions' => '', 
     'fields' => '', 
     'order' => 'created ASC', 
     'limit' => '', 
     'offset' => '', 
     'exclusive' => '', 
     'finderQuery' => '', 
     'counterQuery' => '' 
    ),