From 8a674fb83fa2dd80bc653745e03b24450a9cf68d Mon Sep 17 00:00:00 2001 From: xue <> Date: Tue, 6 Mar 2007 20:40:51 +0000 Subject: changed the way to specify active record table. --- framework/Data/ActiveRecord/Exceptions/messages.txt | 2 +- framework/Data/ActiveRecord/TActiveRecord.php | 4 ++-- framework/Data/ActiveRecord/TActiveRecordGateway.php | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'framework/Data/ActiveRecord') diff --git a/framework/Data/ActiveRecord/Exceptions/messages.txt b/framework/Data/ActiveRecord/Exceptions/messages.txt index 84b58fe5..9ab1693e 100644 --- a/framework/Data/ActiveRecord/Exceptions/messages.txt +++ b/framework/Data/ActiveRecord/Exceptions/messages.txt @@ -9,7 +9,7 @@ ar_no_primary_key_found = Table '{0}' does not contain any primary key fiel ar_primary_key_is_scalar = Primary key '{1}' in table '{0}' is NOT a composite key, invalid value '{2} used. ar_invalid_db_connection = Missing or invalid default database connection for ActiveRecord class '{0}', default connection is set by the DbConnection property of TActiveRecordManager. ar_mismatch_args_exception = ActiveRecord finder method '{0}' expects {1} parameters but found only {2} parameters instead. -ar_invalid_tablename_property = ActiveRecord tablename property '{0}::${1}' must be static and not null. +ar_invalid_tablename_property = Constant {0}::{1} must be a valid database table name. ar_value_must_not_be_null = Property '{0}::${2}' must not be null as defined by column '{2}' in table '{1}'. ar_missing_pk_values = Missing primary key values in forming IN(key1, key2, ...) for table '{0}'. ar_pk_value_count_mismatch = Composite key value count mismatch in forming IN( (key1, key2, ..), (key3, key4, ..)) for table '{0}'. diff --git a/framework/Data/ActiveRecord/TActiveRecord.php b/framework/Data/ActiveRecord/TActiveRecord.php index 4e06f645..cbf02058 100644 --- a/framework/Data/ActiveRecord/TActiveRecord.php +++ b/framework/Data/ActiveRecord/TActiveRecord.php @@ -35,11 +35,11 @@ Prado::using('System.Data.ActiveRecord.TActiveRecordCriteria'); * * class UserRecord extends TActiveRecord * { + * const TABLE='users'; //optional table name. + * * public $username; //corresponds to the fieldname in the table * public $email; * - * public static final $_tablename='users'; //optional table name. - * * //returns active record finder instance * public static function finder($className=__CLASS__) * { diff --git a/framework/Data/ActiveRecord/TActiveRecordGateway.php b/framework/Data/ActiveRecord/TActiveRecordGateway.php index c925f3c9..f9cc5bbd 100644 --- a/framework/Data/ActiveRecord/TActiveRecordGateway.php +++ b/framework/Data/ActiveRecord/TActiveRecordGateway.php @@ -25,9 +25,9 @@ class TActiveRecordGateway extends TComponent private $_tables=array(); //meta data cache. /** - * Property name for optional table name in TActiveRecord. + * Constant name for specifying optional table name in TActiveRecord. */ - const PROPERTY_TABLE_NAME='_tablename'; + const TABLE_CONST='TABLE'; /** * Record gateway constructor. @@ -47,7 +47,7 @@ class TActiveRecordGateway extends TComponent } /** - * Gets the table name from the $_tablename property of the active record + * Gets the table name from the 'TABLE' constant of the active record * class if defined, otherwise use the class name as table name. * @param TActiveRecord active record instance * @return string table name for the given record class. @@ -55,12 +55,12 @@ class TActiveRecordGateway extends TComponent public function getTableName(TActiveRecord $record) { $class = new ReflectionClass($record); - if($class->hasProperty(self::PROPERTY_TABLE_NAME)) + if($class->hasConstant(self::TABLE_CONST)) { - $value = $class->getProperty(self::PROPERTY_TABLE_NAME)->getValue(); - if($value===null) + $value = $class->getConstant(self::TABLE_CONST); + if(empty($value)) throw new TActiveRecordException('ar_invalid_tablename_property', - get_class($record),self::PROPERTY_TABLE_NAME); + get_class($record),self::TABLE_CONST); return $value; } else -- cgit v1.2.3