summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorxue <>2007-03-06 20:40:51 +0000
committerxue <>2007-03-06 20:40:51 +0000
commit8a674fb83fa2dd80bc653745e03b24450a9cf68d (patch)
tree83f72026185075b0ffacf5c1996d3424b0e2f31f /framework
parent2ab695a553abf26e530f5e97c1ea357233d80998 (diff)
changed the way to specify active record table.
Diffstat (limited to 'framework')
-rw-r--r--framework/Data/ActiveRecord/Exceptions/messages.txt2
-rw-r--r--framework/Data/ActiveRecord/TActiveRecord.php4
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordGateway.php14
-rwxr-xr-xframework/prado-cli.php3
4 files changed, 11 insertions, 12 deletions
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');
* <code>
* 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
diff --git a/framework/prado-cli.php b/framework/prado-cli.php
index 8ede48ab..c5cb7d58 100755
--- a/framework/prado-cli.php
+++ b/framework/prado-cli.php
@@ -647,7 +647,6 @@ EOD;
protected function generateClass($properties, $tablename, $class)
{
$props = implode("\n", $properties);
- $table = '$_tablename=\''.$tablename.'\'';
$date = date('Y-m-d h:i:s');
return <<<EOD
<?php
@@ -656,7 +655,7 @@ return <<<EOD
*/
class $class extends TActiveRecord
{
- public static $table;
+ const TABLE='$tablename';
$props