des1roer
@des1roer
ученье - свет, а неученье - приятный полумрак

Yii eadvancedarbehavior + postgres — как подключить?

Решил создавать проект на постгресе. Но вот пробую подключить связь многие ко многим
des1roer.blogspot.ru/2015/03/yii-yii-for-dummies-c...
и получаю
CDbCommand не удалось исполнить SQL-запрос: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "ignore"
LINE 1: insert ignore into t_mim(id_engine , id_book) values ('1', '...
^. The SQL statement executed was: insert ignore into t_mim(id_engine , id_book) values ('1', '1'),('1', '2')
Естественно, в PG нет никакого ignore. перелопачивать за разработчиков это расширение ни навыков, ни желания.
Кто-нибудь пользовался бехавиором в связке с постгрей? Про мускул не спрашивайте.
Кстати вот мой вырвиглазный велосипед

_form.php

<?php echo CHtml::label('комплектность', 'complect'); ?>
        <?php
        $criteria = new CDbCriteria();
        $criteria->addInCondition('handbook_h_id', array('4'));
        $type_list = CHtml::listData(Handbook::model()->findAll($criteria), 'h_id', 'h_value');

        if (isset($model->e_id))
        {
            $arr = Mim::model()->findAll("engine_e_id=:id", array(':id' => $model->e_id));
        }

        if (isset($arr))
        {
            for ($i = 0; $i < count($arr); $i++)
            {
                $arr_bit[] = $arr[$i]->handbook_h_id;
            }
        }
        else
            $arr_bit = array();


        echo CHtml::checkBoxList('im_id', $arr_bit, $type_list, array(
            'template' => '{input} {labelTitle}',
            'class' => 'chclass',
                )
        ); //просто рисуем чекбокслитс из базы
        ?>


controller

public function actionCreate()
    {
        $model = new Engine;

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);

        if (isset($_POST['Engine']))
        {
            $model->attributes = $_POST['Engine'];
            if ($model->save())
            {                
                if (isset($_POST['im_id']))
                {
                    $command = Yii::app()->db->createCommand();
                    foreach ($_POST['im_id'] as $check)
                    {
                        $Ids = $_POST['im_id'];
                    };
                    for ($i = 0; $i < count($Ids); $i++)
                    {
                        $command->insert('mim', array(
                            'engine_e_id' => $model->e_id, ////
                            'handbook_h_id' => (int) $Ids[$i], ////
                        ));
                    }
                }

                $this->redirect(array('view', 'id' => $model->e_id));
            }
        }

        $this->render('create', array(
            'model' => $model,
        ));
    }

    /**
     * Updates a particular model.
     * If update is successful, the browser will be redirected to the 'view' page.
     * @param integer $id the ID of the model to be updated
     */
    public function actionUpdate($id)
    {
        $model = $this->loadModel($id);

        // Uncomment the following line if AJAX validation is needed
        // $this->performAjaxValidation($model);
        if (isset($_POST['Engine']))
        {
            $model->attributes = $_POST['Engine'];
           
            if ($model->save())
            {
                $command = Yii::app()->db->createCommand();
                $command->delete('mim', 'engine_e_id=:id', array(':id' => $model->e_id));
                if (isset($_POST['im_id']))
                {
                    foreach ($_POST['im_id'] as $check)
                    {
                        $Ids = $_POST['im_id'];
                    };
                    for ($i = 0; $i < count($Ids); $i++)
                    {
                        $command->insert('mim', array(
                            'engine_e_id' => $model->e_id, ////
                            'handbook_h_id' => (int) $Ids[$i], ////
                        ));
                    }
                }
                $this->redirect(array('view', 'id' => $model->e_id));
            }
        }

        $this->render('update', array(
            'model' => $model,
        ));
    }
  • Вопрос задан
  • 272 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы