yii2-relation-trait icon indicating copy to clipboard operation
yii2-relation-trait copied to clipboard

SaveAll() function Deletes Related Records unexpectedly.

Open IvandaNothabeer opened this issue 2 years ago • 1 comments

The Saveall() function will delete related records if those relations were not completely found by LoadAll() or were not fully presented on the CRUD view.

Example ....

  • "Owner" -has many- "Cars" -has many- "Parts"
  • CRUD form has sub forms for "Cars" and "Parts"

If there are several hundred "parts" for one "car" and several "cars" for each "owner", then the list of "Parts" records on the CRUD can run into hundreds or thousands of records. The List of "Parts" on the CRUD view can / will be incomplete.

If a new "car" is added or the "owner" record is then saved, the missing "parts" records from the CRUD view will be deleted from the database.

In an extreme case, if you LoadAll(), including "Parts" , but do not display the "Parts" records in the CRUD view, then SaveAll() will delete EVERY "parts" record.

This is probably the same problem that occured in this bug report #67

IvandaNothabeer avatar Jan 16 '23 23:01 IvandaNothabeer

#54 Same issue

IvandaNothabeer avatar Jan 17 '23 10:01 IvandaNothabeer