diff options
Diffstat (limited to 'framework/Data/ActiveRecord/TActiveRecord.php')
-rw-r--r-- | framework/Data/ActiveRecord/TActiveRecord.php | 29 |
1 files changed, 25 insertions, 4 deletions
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; * } * </code> * 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'); * } * </code> * + * Since v3.1.3 you can also define a method that returns the table name. + * <code> + * class UserRecord extends TActiveRecord + * { + * public function table() + * { + * return 'users'; + * } + * + * } + * </code> + * * @author Wei Zhuo <weizho[at]gmail[dot]com> * @version $Id$ * @package System.Data.ActiveRecord @@ -318,6 +330,14 @@ abstract class TActiveRecord extends TComponent } /** + * @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 * comparison of their values. Set $strict=true for identity comparison (===). @@ -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 } } -?> |