@@ -40,6 +40,43 @@ The ``insertBatch()`` and ``updateBatch()`` methods now honor model settings lik
4040``updateOnlyChanged `` and ``allowEmptyInserts ``. This change ensures consistent handling
4141across all insert/update operations.
4242
43+ Primary Key Validation
44+ ^^^^^^^^^^^^^^^^^^^^^^
45+
46+ The ``insert() `` and ``insertBatch() `` (when ``useAutoIncrement `` is disabled), ``update() ``,
47+ and ``delete() `` methods now validate primary key values **before ** executing database queries.
48+ Invalid primary key values will now throw ``InvalidArgumentException `` instead of
49+ ``DatabaseException ``.
50+
51+ **What changed: **
52+
53+ - **Exception type: ** Invalid primary keys now throw ``InvalidArgumentException `` with
54+ specific error messages instead of generic ``DatabaseException `` from the database layer.
55+ - **Validation timing: **
56+
57+ - For ``update() `` and ``delete() ``: Validation happens **before ** the ``beforeUpdate ``/``beforeDelete ``
58+ events and before any database queries are executed.
59+ - For ``insert() `` and ``insertBatch() `` (when auto-increment is disabled): Validation happens
60+ **after ** the ``beforeInsert `` event but **before ** database queries are executed.
61+
62+ - **Invalid values: ** The following values are now explicitly rejected as primary keys:
63+
64+ - ``null `` (for insert when auto-increment is disabled)
65+ - ``0 `` (integer zero)
66+ - ``'0' `` (string zero)
67+ - ``'' `` (empty string)
68+ - ``true `` and ``false `` (booleans)
69+ - ``[] `` (empty array)
70+ - Nested arrays (e.g., ``[[1, 2]] ``)
71+ - Arrays containing any of the above invalid values
72+
73+ This change improves error reporting by providing specific validation messages
74+ (e.g., "Invalid primary key: 0 is not allowed") instead of generic database errors, and
75+ prevents invalid queries from reaching the database.
76+
77+ If you need to allow some of these values for the primary key, you can override the
78+ ``validateID() `` method in your model.
79+
4380Interface Changes
4481=================
4582
0 commit comments