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

ConflictAlgorithm.replace deletes the row with FOREIGN KEY ON DELETE CASCADE ON UPDATE NO ACTION #1099

Open
danielrrys opened this issue Apr 19, 2024 · 0 comments

Comments

@danielrrys
Copy link

I already use the ConflictAlgorithm example :

int recordId = await db.insert('Product', {'title': 'Example 1'});
await db.insert('ProductImage', {'productId': recordId, 'imageUrl': 'someUrlHere'});
await db.insert('ProductImage', {'productId': recordId, 'imageUrl': 'someUpdatedUrlHere'}, conflictAlgorithm: ConflictAlgorithm.replace);

But what happens when my tables are like this :

CREATE TABLE Product (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  title TEXT)
  
CREATE TABLE ProductImage (
  productId INTEGER PRIMARY KEY,
  imageUrl TEXT,
  FOREIGN KEY (productId) REFERENCES Product(id) ON DELETE CASCADE ON UPDATE NO ACTION
)

When i use ConflictAlgorithm.replace, my ProductImage is deleted, instead of doing nothing with ON UPDATE NO ACTION, but i see the documentation the pre-existing rows that are causing the constraint violation are removed prior to inserting or updating the current row.

So the only way to do this is not using the .replace and do 2 QUERY DB ?

if (exists) {
// .update
} else {
// .insert
}

There is no way to do it with the .replace ?

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

1 participant