From ee8c40ebe147f1519534649eb955634c7471254b Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Thu, 27 Dec 2012 22:29:13 +0100 Subject: [PATCH] Add function to spawn a new object from a custom query --- class.databaserecord.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/class.databaserecord.php b/class.databaserecord.php index 657011e..d4707ad 100644 --- a/class.databaserecord.php +++ b/class.databaserecord.php @@ -611,6 +611,22 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass return $export_array; } + public static function CreateFromQuery($query, $parameters = array(), $expiry = 0) + { + global $database; + + $result = $database->CachedQuery($query, $parameters, $expiry); + + if($result) + { + return new self($result); + } + else + { + throw new NotFoundException("No results for specified query."); + } + } + // Define events protected function EventConstructed() { }