首页 文章

用cakephp命令multidimentional数组找到所有

提问于
浏览
-1

我的故事与一个有很多关系的章节有关,我有一个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

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

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

相关问题