使用cakephp命令多维数组查找全部

时间:2014-06-16 12:22:43

标签: php arrays cakephp

我的故事与一个有很多关系的章节有关 我有一个StoryChapter模型。

我找到了所有故事的结果:

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()
)

我希望find函数只通过创建的desc命令StoryChapter而不影响找到的故事的顺序。

我希望你理解我的意思。

谢谢

1 个答案:

答案 0 :(得分:0)

我通过在Story模型中添加hasMany数组中的顺序来解决问题

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