From 6228873cf9d6471463d2413e7dfd7447f759baf2 Mon Sep 17 00:00:00 2001 From: "christophe.boulain" <> Date: Wed, 3 Dec 2008 14:22:03 +0000 Subject: Merge from trunk --- framework/Data/ActiveRecord/TActiveRecord.php | 29 +++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'framework/Data/ActiveRecord/TActiveRecord.php') diff --git a/framework/Data/ActiveRecord/TActiveRecord.php b/framework/Data/ActiveRecord/TActiveRecord.php index 370dd69a..fa134a9f 100644 --- a/framework/Data/ActiveRecord/TActiveRecord.php +++ b/framework/Data/ActiveRecord/TActiveRecord.php @@ -79,7 +79,7 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelationContext'); * 'email_address'=>'email', * ); * public $username; - * pulbic $email; + * public $email; * } * * In the above, the 'users' table consists of 'user_id' and 'email_address' columns, @@ -129,6 +129,18 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelationContext'); * } * * + * Since v3.1.3 you can also define a method that returns the table name. + * + * class UserRecord extends TActiveRecord + * { + * public function table() + * { + * return 'users'; + * } + * + * } + * + * * @author Wei Zhuo * @version $Id$ * @package System.Data.ActiveRecord @@ -317,6 +329,14 @@ abstract class TActiveRecord extends TComponent $this->_connection=$connection; } + /** + * @return TDbTableInfo the meta information of the table associated with this AR class. + */ + public function getRecordTableInfo() + { + return $this->getRecordGateway()->getRecordTableInfo($this); + } + /** * Compare two records using their primary key values (all column values if * table does not defined primary keys). The default uses simple == for @@ -329,7 +349,7 @@ abstract class TActiveRecord extends TComponent { if($record===null || get_class($this)!==get_class($record)) return false; - $tableInfo = $this->getRecordGateway()->getRecordTableInfo($this); + $tableInfo = $this->getRecordTableInfo(); $pks = $tableInfo->getPrimaryKeys(); $properties = count($pks) > 0 ? $pks : $tableInfo->getColumns()->getKeys(); $equals=true; @@ -378,7 +398,7 @@ abstract class TActiveRecord extends TComponent /** * @return TActiveRecordGateway record table gateway. */ - public static function getRecordGateway() + public function getRecordGateway() { return TActiveRecordManager::getInstance()->getRecordGateway(); } @@ -552,6 +572,7 @@ abstract class TActiveRecord extends TComponent { $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; $criteria = $this->getRecordCriteria($criteria,$parameters, $args); + $criteria->setLimit(1); $data = $this->getRecordGateway()->findRecordsByCriteria($this,$criteria); return $this->populateObject($data); } @@ -629,6 +650,7 @@ abstract class TActiveRecord extends TComponent { $args = func_num_args() > 1 ? array_slice(func_get_args(),1) : null; $criteria = $this->getRecordCriteria($sql,$parameters, $args); + $criteria->setLimit(1); $data = $this->getRecordGateway()->findRecordBySql($this,$criteria); return $this->populateObject($data); } @@ -1000,4 +1022,3 @@ class TActiveRecordChangeEventParameter extends TEventParameter } } -?> -- cgit v1.2.3