@@ -158,7 +158,7 @@ which I want to define like this::
158
158
$this->getOwner()->addField('created_dts', ['type' => 'datetime', 'default' => new \DateTime()]);
159
159
160
160
$this->getOwner()->hasOne('created_by_user_id', 'User');
161
- if(isset($this->getApp()->user) && $this->getApp()->user->loaded ()) {
161
+ if(isset($this->getApp()->user) && $this->getApp()->user->isLoaded ()) {
162
162
$this->getOwner()->getField('created_by_user_id')->default = $this->getApp()->user->getId();
163
163
}
164
164
@@ -167,7 +167,7 @@ which I want to define like this::
167
167
$this->getOwner()->addField('updated_dts', ['type' => 'datetime']);
168
168
169
169
$this->getOwner()->onHook(Model::HOOK_BEFORE_UPDATE, function($m, $data) {
170
- if(isset($this->getApp()->user) && $this->getApp()->user->loaded ()) {
170
+ if(isset($this->getApp()->user) && $this->getApp()->user->isLoaded ()) {
171
171
$data['updated_by'] = $this->getApp()->user->getId();
172
172
}
173
173
$data['updated_dts'] = new \DateTime();
@@ -238,10 +238,8 @@ Start by creating a class::
238
238
}
239
239
}
240
240
241
- function softDelete($m) {
242
- if (!$m->loaded()) {
243
- throw (new \Atk4\Core\Exception('Model must be loaded before soft-deleting'))->addMoreInfo('model', $m);
244
- }
241
+ function softDelete(Model $m) {
242
+ $m->assertIsLoaded();
245
243
246
244
$id = $m->getId();
247
245
if ($m->hook('beforeSoftDelete') === false) {
@@ -257,10 +255,8 @@ Start by creating a class::
257
255
return $m;
258
256
}
259
257
260
- function restore($m) {
261
- if (!$m->loaded()) {
262
- throw (new \Atk4\Core\Exception(['Model must be loaded before restoring'))->addMoreInfo('model', $m);
263
- }
258
+ function restore(Model $m) {
259
+ $m->assertIsLoaded();
264
260
265
261
$id = $m->getId();
266
262
if ($m->hook('beforeRestore') === false) {
@@ -348,9 +344,7 @@ before and just slightly modifying it::
348
344
}
349
345
350
346
function softDelete(Model $m) {
351
- if (!$m->loaded()) {
352
- throw (new \Atk4\Core\Exception('Model must be loaded before soft-deleting'))->addMoreInfo('model', $m);
353
- }
347
+ $m->assertIsLoaded();
354
348
355
349
$id = $m->getId();
356
350
@@ -364,10 +358,8 @@ before and just slightly modifying it::
364
358
$m->breakHook(false); // this will cancel original delete()
365
359
}
366
360
367
- function restore($m) {
368
- if (!$m->loaded()) {
369
- throw (new \Atk4\Core\Exception('Model must be loaded before restoring'))->addMoreInfo('model', $m);
370
- }
361
+ function restore(Model $m) {
362
+ $m->assertIsLoaded();
371
363
372
364
$id = $m->getId();
373
365
if ($m->hook('beforeRestore') === false) {
@@ -436,7 +428,7 @@ inside your model are unique::
436
428
$mm->addCondition($mm->id_field != $this->id);
437
429
$mm = $mm->tryLoadBy($field, $m->get($field));
438
430
439
- if ($mm->loaded ()) {
431
+ if ($mm->isLoaded ()) {
440
432
throw (new \Atk4\Core\Exception('Duplicate record exists'))
441
433
->addMoreInfo('field', $field)
442
434
->addMoreInfo('value', $m->get($field));
@@ -572,12 +564,12 @@ payment towards a most suitable invoice::
572
564
// See if any invoices match by 'reference';
573
565
$invoices = $invoices->tryLoadBy('reference', $this->get('reference'));
574
566
575
- if (!$invoices->loaded ()) {
567
+ if (!$invoices->isLoaded ()) {
576
568
577
569
// otherwise load any unpaid invoice
578
570
$invoices = $invoices->tryLoadAny();
579
571
580
- if(!$invoices->loaded ()) {
572
+ if(!$invoices->isLoaded ()) {
581
573
582
574
// couldn't load any invoice.
583
575
return;
0 commit comments