|
|
@@ -15,6 +15,7 @@
|
|
|
namespace Cake\Datasource;
|
|
|
|
|
|
use Cake\Collection\Iterator\MapReduce;
|
|
|
+use Cake\Datasource\Exception\RecordNotFoundException;
|
|
|
use Cake\Datasource\QueryCacher;
|
|
|
use Cake\Datasource\RepositoryInterface;
|
|
|
|
|
|
@@ -329,6 +330,23 @@ trait QueryTrait {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Get the first result from the executing query or raise an exception.
|
|
|
+ *
|
|
|
+ * @throws \Cake\Datasource\RecordNotFoundException When there is no first record.
|
|
|
+ * @return mixed The first result from the ResultSet.
|
|
|
+ */
|
|
|
+ public function firstOrFail() {
|
|
|
+ $entity = $this->first();
|
|
|
+ if ($entity) {
|
|
|
+ return $entity;
|
|
|
+ }
|
|
|
+ throw new RecordNotFoundException(sprintf(
|
|
|
+ 'Record not found in table "%s"',
|
|
|
+ $this->repository()->table()
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+/**
|
|
|
* Returns an array with the custom options that were applied to this query
|
|
|
* and that were not already processed by another method in this class.
|
|
|
*
|