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
Ignore duplicates on save #7073
Comments
This is the documentation for
In your example, is the error resulting because you are trying to save a new entity with the same name as an existing entity? |
The error is happening because the column Example: Database
Entities
This throws the error |
TypeORM has no idea what your intent is when you try to save the new If you are trying to save a post that already exists, then you should pass the id value as well. What happens if you do this?
|
I don't think you understand my issue. I do not want to update the post, I want it to just not throw the error when it runs into a Also I can not pass an Basically, if I want to save an array of |
Firstly, if you only intend on inserting entities you can use Secondly, if you want it to ignore errors like this, that is a custom behavior so you will have to use a query builder like so: Posts.createQueryBuilder('posts')
.insert()
.values(posts)
.orIgnore()
.execute(); This is unlikely to ever be supported using |
Can use this.yourEntityRepository
.createQueryBuilder()
.insert()
.orIgnore(true)
.into(YourEntity)
.values(arrayData)
.updateEntity(false)
.execute(); |
Currently if you run
Model.save(models)
and theModel
class has aunique
constraint it won't save anything, is there anyway to just ignore duplicates and still mass save the rest. I know I could loop over them and save 1 by 1 but this is sooooo much slower.This means that if I have
Post 1
,Post 2
,Post 3
... etc. None will get saved ifPost 7
errors as a duplicate.The text was updated successfully, but these errors were encountered: