You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: split id-update into upsert vs delete-then-insert strategies
The delete_all recipe isn't obsolete — it's a different tool (DB-agnostic,
validation-friendly, full-row replace). Present both approaches with their
trade-offs and lead with the native :on_duplicate_key_update upsert, trimming
the adapter notes to the PG/SQLite vs MySQL option shapes.
*Turn`validate` off for id-based upserts. `activerecord-import` runs
266
-
uniqueness validations against the very rows the upsert is about to overwrite,
267
-
so a model-level `validates_uniqueness_of` would otherwise reject the update.
254
+
* Only the columns you list are updated; other columns on the existing row keep their values.
255
+
* Use `validate: false` — `activerecord-import` runs uniqueness validations against the very rows the upsert is about to overwrite, so `validates_uniqueness_of` would otherwise reject the update.
268
256
* Active Record callbacks are not fired for bulk imports.
269
257
258
+
###### Delete-then-insert (any database)
259
+
260
+
When you can't rely on upsert support — an older database, or you need your model
261
+
validations to run — delete the colliding rows just before each batch insert.
262
+
The old row is gone before the insert, so `validates_uniqueness_of` doesn't trip,
263
+
at the cost of a second query and full-row **replacement** (columns absent from
0 commit comments