9
9
use Yiisoft \Db \Constant \ColumnType ;
10
10
use Yiisoft \Db \Exception \Exception ;
11
11
use Yiisoft \Db \Exception \InvalidArgumentException ;
12
+ use Yiisoft \Db \Exception \InvalidCallException ;
12
13
use Yiisoft \Db \Exception \InvalidConfigException ;
13
14
14
15
interface ActiveRecordInterface
@@ -195,6 +196,8 @@ public function hasProperty(string $name): bool;
195
196
196
197
/**
197
198
* Inserts a row into the associated database table using the property values of this record.
199
+ * You may specify the properties to be inserted as list of name or name-value pairs.
200
+ * If name-value pair specified, the corresponding property values will be modified.
198
201
*
199
202
* Only the {@see newValues() changed property values} will be inserted into a database.
200
203
*
@@ -210,15 +213,22 @@ public function hasProperty(string $name): bool;
210
213
* $customer->insert();
211
214
* ```
212
215
*
213
- * @param array|null $propertyNames List of property names that need to be saved. Defaults to `null`, meaning all
214
- * changed property values will be saved.
216
+ * To insert a customer record with specific properties:
217
+ *
218
+ * ```php
219
+ * $customer->insert(['name' => $name, 'email' => $email]);
220
+ * ```
221
+ *
222
+ * @param array|null $properties List of property names or name-values pairs that need to be saved.
223
+ * Defaults to `null`, meaning all changed property values will be saved.
215
224
*
225
+ * @throws InvalidCallException If the record {@see isNewRecord() is not new}.
216
226
* @throws InvalidConfigException
217
227
* @throws Throwable In case insert failed.
218
228
*
219
229
* @return bool Whether the record is inserted successfully.
220
230
*/
221
- public function insert (array |null $ propertyNames = null ): bool ;
231
+ public function insert (array |null $ properties = null ): bool ;
222
232
223
233
/**
224
234
* Checks if any property returned by {@see propertyNames()} method has changed.
@@ -358,9 +368,13 @@ public function relationQuery(string $name): ActiveQueryInterface;
358
368
public function resetRelation (string $ name ): void ;
359
369
360
370
/**
361
- * Saves the current record.
371
+ * Saves the changes to this active record into the associated database table.
372
+ * You may specify the properties to be updated as list of name or name-value pairs.
373
+ * If name-value pair specified, the corresponding property values will be modified.
362
374
*
363
- * This method will call {@see insert()} when {@see isNewRecord()|isNewRecord} is true, or {@see update()} when
375
+ * Only the {@see newValues() changed property values} will be saved into a database.
376
+ *
377
+ * This method will call {@see insert()} when {@see isNewRecord()} is true, or {@see update()} when
364
378
* {@see isNewRecord()|isNewRecord} is false.
365
379
*
366
380
* For example, to save a customer record:
@@ -372,12 +386,18 @@ public function resetRelation(string $name): void;
372
386
* $customer->save();
373
387
* ```
374
388
*
375
- * @param array|null $propertyNames List of property names that need to be saved. Defaults to `null`,
376
- * meaning all changed property values will be saved.
389
+ * To save a customer record with specific properties:
390
+ *
391
+ * ```php
392
+ * $customer->save(['name' => $name, 'email' => $email]);
393
+ * ```
394
+ *
395
+ * @param array|null $properties List of property names or name-values pairs that need to be saved.
396
+ * Defaults to `null`, meaning all changed property values will be saved.
377
397
*
378
398
* @return bool Whether the saving succeeded (that's no validation errors occurred).
379
399
*/
380
- public function save (array |null $ propertyNames = null ): bool ;
400
+ public function save (array |null $ properties = null ): bool ;
381
401
382
402
/**
383
403
* Sets the named property value.
@@ -400,7 +420,7 @@ public function set(string $propertyName, mixed $value): void;
400
420
* For example, to update a customer record:
401
421
*
402
422
* ```php
403
- * $customer = new Customer( );
423
+ * $customer = ( new ActiveQuery( Customer::class))->findByPk(1 );
404
424
* $customer->name = $name;
405
425
* $customer->email = $email;
406
426
* $customer->update();
@@ -409,9 +429,8 @@ public function set(string $propertyName, mixed $value): void;
409
429
* To update a customer record with specific properties:
410
430
*
411
431
* ```php
412
- * $customer = new Customer();
413
- * $customer->update(['name' => $name, 'email' => $email]);
414
- * ```
432
+ * $customer->update(['name' => $name, 'email' => $email]);
433
+ * ```
415
434
*
416
435
* Note that it's possible the update doesn't affect any row in the table.
417
436
* In this case, this method will return 0.
@@ -428,6 +447,7 @@ public function set(string $propertyName, mixed $value): void;
428
447
* @param array|null $properties List of property names or name-values pairs that need to be saved.
429
448
* Defaults to `null`, meaning all changed property values will be saved.
430
449
*
450
+ * @throws InvalidCallException If the record {@see isNewRecord() is new}.
431
451
* @throws OptimisticLockException If the instance implements {@see OptimisticLockInterface} and the data being
432
452
* updated is outdated.
433
453
* @throws Throwable In case update failed.
0 commit comments