Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in update and delete in child relation #135

Open
cufano opened this issue Jan 4, 2018 · 2 comments
Open

Bug in update and delete in child relation #135

cufano opened this issue Jan 4, 2018 · 2 comments

Comments

@cufano
Copy link

cufano commented Jan 4, 2018

Hello,

I'm trying to test the extension with a simple parent-child relation One-to-Many. I create the models and also the controller and views. All is fine but the Update and Delete operations in child table. When I delete or change any content or add any new record in child table and Update, it generates duplicate entry in the child table.

These are my tables config:

Order Table:
id int 10 Auto Increment, Not Null, Primary Key
order_date date 0 Not Null
qty int 6 Allow Null, NULL as Default

Products Table:
id bigint 15 Auto Increment, Not Null, Primery Key
order_id int 10 Not Null, Foreign Key id in Order table
qty int 4 Not Null
name varchar 150 Not Null

I'm also using RelationTrait, so in Update action is simple as:
`public function actionUpdate($id)
{
$model = $this->findModel($id);

    if ($model->loadAll(Yii::$app->request->post()) && $model->saveAll()) {
        return $this->redirect(['view', 'id' => $model->id]);
    } else {
        return $this->render('update', [
            'model' => $model,
        ]);
    }
}`

So it seems than in SaveAll() it is not deleting old records or adding new ones.

Reviewing the log, it seems that when Update the model it first deletes all records before insert new ones, and the Delete query is generating an error: "Impossible WHERE". The SQL is: DELETE FROM product WHERE (order_id=8) AND (id<>NULL)

It seems that the ('id'<>NULL) clause in the query is generating the error, because if I run the query in the database, no records are selected. But if I use only DELETE FROM product WHERE (order_id=8), the query is running fine.

What I'm doing wrong?

@gomegs
Copy link

gomegs commented Jan 24, 2018

Hi, any luck finding a fix or work-around for this issue?

@alvarolordelo
Copy link

alvarolordelo commented Mar 1, 2018

@cufano @gomegs take a look at my issue, I already solved that matter and suggested a correction.

#138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants