Skip to content

Commit 148165e

Browse files
authored
add rnf message (#111)
1 parent ac94fce commit 148165e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"keywords": ["activerecord", "orm"],
66
"homepage": "http://www.phpactiverecord.org/",
77
"license": "MIT",
8-
"version": "2.0.0-rc.8",
8+
"version": "2.0.0-rc.9",
99
"require": {
1010
"php": ">=8.1.0",
1111
"ext-bcmath": "*"

lib/Relation.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,11 @@ public function distinct(bool $distinct=true): Relation
669669
return $this;
670670
}
671671

672+
protected function rnf(): RecordNotFound
673+
{
674+
return new RecordNotFound("Couldn't find " . $this->className . ' without an ID');
675+
}
676+
672677
/**
673678
* Find by id - This can either be a specific id (1),
674679
* a list of ids (1, 5, 6), or an array of ids ([5, 6, 10]).
@@ -698,7 +703,7 @@ public function distinct(bool $distinct=true): Relation
698703
public function find(): Model|array
699704
{
700705
if ($this->isNone) {
701-
throw new RecordNotFound('tbd');
706+
throw $this->rnf();
702707
}
703708

704709
$args = func_get_args();
@@ -723,7 +728,7 @@ public function find(): Model|array
723728
$options['conditions'][] = $this->pk_conditions($args);
724729

725730
if (is_array($args) && 0 === count($args)) {
726-
throw new RecordNotFound("Couldn't find " . $this->className . ' without an ID');
731+
throw $this->rnf();
727732
}
728733

729734
$list = $this->_to_a($options);
@@ -733,7 +738,7 @@ public function find(): Model|array
733738
throw new RecordNotFound('found ' . count($list) . ', but was looking for ' . count($args));
734739
}
735740

736-
return $single ? ($list[0] ?? throw new RecordNotFound('tbd')) : $list;
741+
return $single ? ($list[0] ?? throw $this->rnf()) : $list;
737742
}
738743

739744
/**

0 commit comments

Comments
 (0)