@@ -95,18 +95,18 @@ public function delete(): int
95
95
public function deleteAll (array $ condition = [], array $ params = []): int
96
96
{
97
97
$ command = $ this ->db ()->createCommand ();
98
- $ command ->delete ($ this ->getTableName (), $ condition , $ params );
98
+ $ command ->delete ($ this ->tableName (), $ condition , $ params );
99
99
100
100
return $ command ->execute ();
101
101
}
102
102
103
103
public function equals (ActiveRecordInterface $ record ): bool
104
104
{
105
- if ($ this ->getIsNewRecord () || $ record ->getIsNewRecord ()) {
105
+ if ($ this ->isNewRecord () || $ record ->isNewRecord ()) {
106
106
return false ;
107
107
}
108
108
109
- return $ this ->getTableName () === $ record ->getTableName () && $ this ->getPrimaryKeys () === $ record ->getPrimaryKeys ();
109
+ return $ this ->tableName () === $ record ->tableName () && $ this ->primaryKeyValues () === $ record ->primaryKeyValues ();
110
110
}
111
111
112
112
public function get (string $ propertyName ): mixed
@@ -125,7 +125,7 @@ public function propertyValues(array|null $names = null, array $except = []): ar
125
125
return array_intersect_key ($ this ->propertyValuesInternal (), array_flip ($ names ));
126
126
}
127
127
128
- public function getIsNewRecord (): bool
128
+ public function isNewRecord (): bool
129
129
{
130
130
return $ this ->oldValues === null ;
131
131
}
@@ -180,30 +180,30 @@ public function oldValues(): array
180
180
return $ this ->oldValues ?? [];
181
181
}
182
182
183
- public function getOldPrimaryKey (): float |int |string |null
183
+ public function primaryKeyOldValue (): float |int |string |null
184
184
{
185
185
$ keys = $ this ->primaryKey ();
186
186
187
187
return match (count ($ keys )) {
188
188
1 => $ this ->oldValues [$ keys [0 ]] ?? null ,
189
189
0 => throw new Exception (
190
190
static ::class . ' does not have a primary key. You should either define a primary key for '
191
- . $ this ->getTableName () . ' table or override the primaryKey() method. '
191
+ . $ this ->tableName () . ' table or override the primaryKey() method. '
192
192
),
193
193
default => throw new Exception (
194
- static ::class . ' has multiple primary keys. Use getOldPrimaryKeys () method instead. '
194
+ static ::class . ' has multiple primary keys. Use primaryKeyOldValues () method instead. '
195
195
),
196
196
};
197
197
}
198
198
199
- public function getOldPrimaryKeys (): array
199
+ public function primaryKeyOldValues (): array
200
200
{
201
201
$ keys = $ this ->primaryKey ();
202
202
203
203
if (empty ($ keys )) {
204
204
throw new Exception (
205
205
static ::class . ' does not have a primary key. You should either define a primary key for '
206
- . $ this ->getTableName () . ' table or override the primaryKey() method. '
206
+ . $ this ->tableName () . ' table or override the primaryKey() method. '
207
207
);
208
208
}
209
209
@@ -216,30 +216,30 @@ public function getOldPrimaryKeys(): array
216
216
return $ values ;
217
217
}
218
218
219
- public function getPrimaryKey (): float |int |string |null
219
+ public function primaryKeyValue (): float |int |string |null
220
220
{
221
221
$ keys = $ this ->primaryKey ();
222
222
223
223
return match (count ($ keys )) {
224
224
1 => $ this ->get ($ keys [0 ]),
225
225
0 => throw new Exception (
226
226
static ::class . ' does not have a primary key. You should either define a primary key for '
227
- . $ this ->getTableName () . ' table or override the primaryKey() method. '
227
+ . $ this ->tableName () . ' table or override the primaryKey() method. '
228
228
),
229
229
default => throw new Exception (
230
- static ::class . ' has multiple primary keys. Use getPrimaryKeys () method instead. '
230
+ static ::class . ' has multiple primary keys. Use primaryKeyValues () method instead. '
231
231
),
232
232
};
233
233
}
234
234
235
- public function getPrimaryKeys (): array
235
+ public function primaryKeyValues (): array
236
236
{
237
237
$ keys = $ this ->primaryKey ();
238
238
239
239
if (empty ($ keys )) {
240
240
throw new Exception (
241
241
static ::class . ' does not have a primary key. You should either define a primary key for '
242
- . $ this ->getTableName () . ' table or override the primaryKey() method. '
242
+ . $ this ->tableName () . ' table or override the primaryKey() method. '
243
243
);
244
244
}
245
245
@@ -259,7 +259,7 @@ public function getPrimaryKeys(): array
259
259
*
260
260
* {@see relationQuery()}
261
261
*/
262
- public function getRelatedRecords (): array
262
+ public function relatedRecords (): array
263
263
{
264
264
return $ this ->related ;
265
265
}
@@ -412,7 +412,7 @@ public function link(string $relationName, ActiveRecordInterface $arClass, array
412
412
$ via = $ relation ->getVia ();
413
413
414
414
if ($ via !== null ) {
415
- if ($ this ->getIsNewRecord () || $ arClass ->getIsNewRecord ()) {
415
+ if ($ this ->isNewRecord () || $ arClass ->isNewRecord ()) {
416
416
throw new InvalidCallException (
417
417
'Unable to link models: the models being linked cannot be newly created. '
418
418
);
@@ -484,11 +484,11 @@ public function link(string $relationName, ActiveRecordInterface $arClass, array
484
484
$ p2 = $ this ->isPrimaryKey (array_values ($ link ));
485
485
486
486
if ($ p1 && $ p2 ) {
487
- if ($ this ->getIsNewRecord () && $ arClass ->getIsNewRecord ()) {
487
+ if ($ this ->isNewRecord () && $ arClass ->isNewRecord ()) {
488
488
throw new InvalidCallException ('Unable to link models: at most one model can be newly created. ' );
489
489
}
490
490
491
- if ($ this ->getIsNewRecord ()) {
491
+ if ($ this ->isNewRecord ()) {
492
492
$ this ->bindModels (array_flip ($ link ), $ this , $ arClass );
493
493
} else {
494
494
$ this ->bindModels ($ link , $ arClass , $ this );
@@ -581,7 +581,7 @@ public function populateRelation(string $name, array|ActiveRecordInterface|null
581
581
*/
582
582
public function refresh (): bool
583
583
{
584
- $ record = $ this ->query ()->findByPk ($ this ->getOldPrimaryKeys ());
584
+ $ record = $ this ->query ()->findByPk ($ this ->primaryKeyOldValues ());
585
585
586
586
return $ this ->refreshInternal ($ record );
587
587
}
@@ -621,7 +621,7 @@ protected function retrieveRelation(string $name): ActiveRecordInterface|array|n
621
621
622
622
public function save (array |null $ propertyNames = null ): bool
623
623
{
624
- if ($ this ->getIsNewRecord ()) {
624
+ if ($ this ->isNewRecord ()) {
625
625
return $ this ->insert ($ propertyNames );
626
626
}
627
627
@@ -660,15 +660,15 @@ public function populateProperties(array $values): void
660
660
}
661
661
662
662
/**
663
- * Sets the value indicating whether the record is new.
663
+ * Marks this record as new.
664
664
*
665
- * @param bool $value Whether the record is new and should be inserted when calling {@see save()}.
665
+ * @param bool $isNewRecord Whether the record is new and should be inserted when calling {@see save()}.
666
666
*
667
- * @see getIsNewRecord ()
667
+ * @see isNewRecord ()
668
668
*/
669
- public function setIsNewRecord (bool $ value ): void
669
+ public function markAsNewRecord (bool $ isNewRecord = true ): void
670
670
{
671
- $ this ->oldValues = $ value ? null : $ this ->propertyValuesInternal ();
671
+ $ this ->oldValues = $ isNewRecord ? null : $ this ->propertyValuesInternal ();
672
672
}
673
673
674
674
/**
@@ -711,7 +711,7 @@ public function updateAll(array $propertyValues, array|string $condition = [], a
711
711
{
712
712
$ command = $ this ->db ()->createCommand ();
713
713
714
- $ command ->update ($ this ->getTableName (), $ propertyValues , $ condition , $ params );
714
+ $ command ->update ($ this ->tableName (), $ propertyValues , $ condition , $ params );
715
715
716
716
return $ command ->execute ();
717
717
}
@@ -753,7 +753,7 @@ public function updateAllCounters(array $counters, array|string $condition = '',
753
753
}
754
754
755
755
$ command = $ this ->db ()->createCommand ();
756
- $ command ->update ($ this ->getTableName (), $ counters , $ condition , $ params );
756
+ $ command ->update ($ this ->tableName (), $ counters , $ condition , $ params );
757
757
758
758
return $ command ->execute ();
759
759
}
@@ -785,7 +785,7 @@ public function updateAllCounters(array $counters, array|string $condition = '',
785
785
*/
786
786
public function updateCounters (array $ counters ): bool
787
787
{
788
- if ($ this ->updateAllCounters ($ counters , $ this ->getOldPrimaryKeys ()) === 0 ) {
788
+ if ($ this ->updateAllCounters ($ counters , $ this ->primaryKeyOldValues ()) === 0 ) {
789
789
return false ;
790
790
}
791
791
@@ -891,7 +891,7 @@ public function unlink(string $relationName, ActiveRecordInterface $arClass, boo
891
891
/** @psalm-var array<array-key, ActiveRecordInterface> $related */
892
892
$ related = $ this ->related [$ relationName ];
893
893
foreach ($ related as $ a => $ b ) {
894
- if ($ arClass ->getPrimaryKeys () === $ b ->getPrimaryKeys ()) {
894
+ if ($ arClass ->primaryKeyValues () === $ b ->primaryKeyValues ()) {
895
895
unset($ this ->related [$ relationName ][$ a ]);
896
896
}
897
897
}
@@ -1071,7 +1071,7 @@ protected function deleteInternal(): int
1071
1071
* We don't check the return value of deleteAll() because it is possible the record is already deleted in
1072
1072
* the database and thus the method will return 0
1073
1073
*/
1074
- $ condition = $ this ->getOldPrimaryKeys ();
1074
+ $ condition = $ this ->primaryKeyOldValues ();
1075
1075
1076
1076
if ($ this instanceof OptimisticLockInterface) {
1077
1077
$ lock = $ this ->optimisticLockPropertyName ();
@@ -1132,7 +1132,7 @@ protected function refreshInternal(array|ActiveRecordInterface|null $record = nu
1132
1132
*/
1133
1133
protected function updateInternal (array |null $ properties = null ): int
1134
1134
{
1135
- if ($ this ->getIsNewRecord ()) {
1135
+ if ($ this ->isNewRecord ()) {
1136
1136
throw new InvalidCallException ('The record is new and cannot be updated. ' );
1137
1137
}
1138
1138
@@ -1157,7 +1157,7 @@ protected function updateInternal(array|null $properties = null): int
1157
1157
return 0 ;
1158
1158
}
1159
1159
1160
- $ condition = $ this ->getOldPrimaryKeys ();
1160
+ $ condition = $ this ->primaryKeyOldValues ();
1161
1161
1162
1162
if ($ this instanceof OptimisticLockInterface) {
1163
1163
$ lock = $ this ->optimisticLockPropertyName ();
@@ -1234,7 +1234,7 @@ protected function resetDependentRelations(string $propertyName): void
1234
1234
unset($ this ->relationsDependencies [$ propertyName ]);
1235
1235
}
1236
1236
1237
- public function getTableName (): string
1237
+ public function tableName (): string
1238
1238
{
1239
1239
$ name = (new ReflectionClass ($ this ))->getShortName ();
1240
1240
/** @var string $name */
0 commit comments