CakePHP, контейнер, группа по - PullRequest
0 голосов
/ 15 июля 2011

У меня есть сценарий, в котором я пытаюсь использовать группирование по модели, связанной с моей основной моделью, с использованиемableable.

Вот мой вывод:

    Array
(
    [Subfirm] => Array
        (
            [id] => 1
            [firm_id] => 1
            [name] => Word Spam Management Fund
            [description] => There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.
            [active] => yes
            [created] => 2011-07-14 18:05:01
            [modified] => 2011-07-14 18:05:01
        )

    [Firm] => Array
        (
            [id] => 1
            [name] => Word Spam
            [description] => Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean dictum neque a arcu ultricies semper. Curabitur lacinia, nisi ac cursus mattis, diam ipsum egestas eros, id pharetra dui quam vel sapien. Fusce tempus mauris eu ligula rutrum rutrum. Cras sit amet metus nisl. Nam feugiat malesuada justo, lacinia mollis nulla iaculis sed. Sed dui sapien, aliquam vel vestibulum eget, suscipit ac dui. Donec et neque dapibus lorem euismod convallis. Sed nec mauris vel velit venenatis fermentum et non velit. Pellentesque tincidunt, nisi vitae sollicitudin malesuada, lectus orci egestas neque, vitae placerat magna nisi eu nulla. Donec eleifend laoreet ligula vitae faucibus. Donec eget felis eros. Nullam ligula nisl, porttitor at viverra a, auctor ullamcorper orci. Fusce vestibulum turpis mollis velit tristique luctus.
            [website] => http://www.wordspam.com
            [active] => yes
            [created] => 2011-07-11 11:33:46
            [firmtype_id] => 1
            [aum] => 600.77
            [modified] => 2011-07-10 22:55:16
            [Firmtype] => Array
                (
                    [id] => 1
                    [name] => Hedge Fund
                    [active] => yes
                    [created] => 2011-07-12 12:30:42
                    [modified] => 2011-07-12 12:30:42
                )

        )

    [Subfirmdetail] => Array
        (
            [0] => Array
                (
                    [id] => 1
                    [subfirm_id] => 1
                    [subfirmdetailtype_id] => 1
                    [value] => 400
                    [date] => 2011-07-14
                    [created] => 2011-07-14 19:09:42
                    [modified] => 2011-07-14 19:09:42
                    [active] => yes
                    [Subfirmdetailtype] => Array
                        (
                            [id] => 1
                            [firmtype_id] => 1
                            [name] => AUM
                            [datatype_id] => 1
                            [created] => 2011-07-14 18:09:23
                            [modified] => 2011-07-14 18:09:23
                            [active] => yes
                            [Datatype] => Array
                                (
                                    [id] => 1
                                    [name] => DOUBLE
                                    [created] => 2011-07-14 18:14:58
                                    [modified] => 2011-07-14 18:14:58
                                    [active] => yes
                                )

                        )

                )

            [1] => Array
                (
                    [id] => 2
                    [subfirm_id] => 1
                    [subfirmdetailtype_id] => 2
                    [value] => 2.34
                    [date] => 2011-07-14
                    [created] => 2011-07-14 19:09:42
                    [modified] => 2011-07-14 19:09:42
                    [active] => yes
                    [Subfirmdetailtype] => Array
                        (
                            [id] => 2
                            [firmtype_id] => 1
                            [name] => Standard Deviation
                            [datatype_id] => 1
                            [created] => 2011-07-14 18:09:23
                            [modified] => 2011-07-14 18:09:23
                            [active] => yes
                            [Datatype] => Array
                                (
                                    [id] => 1
                                    [name] => DOUBLE
                                    [created] => 2011-07-14 18:14:58
                                    [modified] => 2011-07-14 18:14:58
                                    [active] => yes
                                )

                        )

                )

            [2] => Array
                (
                    [id] => 3
                    [subfirm_id] => 1
                    [subfirmdetailtype_id] => 1
                    [value] => 370
                    [date] => 2011-07-11
                    [created] => 2011-07-11 12:00:00
                    [modified] => 2011-07-11 12:00:00
                    [active] => yes
                    [Subfirmdetailtype] => Array
                        (
                            [id] => 1
                            [firmtype_id] => 1
                            [name] => AUM
                            [datatype_id] => 1
                            [created] => 2011-07-14 18:09:23
                            [modified] => 2011-07-14 18:09:23
                            [active] => yes
                            [Datatype] => Array
                                (
                                    [id] => 1
                                    [name] => DOUBLE
                                    [created] => 2011-07-14 18:14:58
                                    [modified] => 2011-07-14 18:14:58
                                    [active] => yes
                                )

                        )

                )

        )

)

I 'Я хотел бы группировать по SubFirmDetail и показывать только самые новые SubFirmDetail в зависимости от subFirmDetailType.Вот код, который я сейчас использую в своем контроллере:

function view($id = null) {
                $this->Subfirm->recursive = -1;
                $data = $this->Subfirm->find('first', array(
                    'contain' => array(
                        'Subfirmdetail' => array(
                            'Subfirmdetailtype' => array(
                                'Datatype',
                            ),
                        ),
                        'Firm' => array(
                            'Firmtype',
                        ),
                    ),
                    'conditions' => array('Subfirm.id' => $id),
                ));
        $this->set('subfirm', $data);
        if (!$id) {
            $this->Session->setFlash(__('Invalid subfirm', true));
            $this->redirect(array('action' => 'index'));
        }
    }

Ответы [ 2 ]

0 голосов
/ 19 июля 2011

В итоге мне пришлось создать представление в базе данных и вывести массив, который я включил в мое условие условия ... Для тех, кто пытался сделать то же самое.

0 голосов
/ 15 июля 2011

Попробуйте это:

function view($id = null) {
                $this->Subfirm->recursive = -1;
                $data = $this->Subfirm->find('first', array(
                    'contain' => array(
                        'Subfirmdetail' => array(
                            'Subfirmdetailtype' => array(
                                'Datatype',
                            ),
                        ),
                        'Firm' => array(
                            'Firmtype',
                        ),
                    ),
                    'conditions' => array('Subfirm.id' => $id),
                    'group' => 'Subfirmdetail',
                    'order' => 'date',
                ));
        $this->set('subfirm', $data);
        if (!$id) {
            $this->Session->setFlash(__('Invalid subfirm', true));
            $this->redirect(array('action' => 'index'));
        }
    }

Или посмотрите ссылки:

...