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.
---
UPGRADE | 14 +++++++++++---
demos/address-book/protected/pages/AddressRecord.php | 2 +-
demos/chat/protected/App_Code/ChatBufferRecord.php | 4 ++--
demos/chat/protected/App_Code/ChatUserRecord.php | 4 ++--
.../protected/controls/Comments/CommentBlock.php | 4 ++--
.../protected/pages/Database/ActiveRecord.page | 16 ++++++++--------
.../protected/pages/Database/Samples/Scaffold/Home.php | 4 ++--
demos/quickstart/protected/pages/Database/Scaffold.page | 4 ++--
demos/quickstart/protected/pages/Database/SqlMap.page | 6 +++---
demos/quickstart/protected/pages/Tutorial/AjaxChat.page | 8 ++++----
.../quickstart/protected/pages/Tutorial/fr/AjaxChat.page | 8 ++++----
framework/Data/ActiveRecord/Exceptions/messages.txt | 2 +-
framework/Data/ActiveRecord/TActiveRecord.php | 4 ++--
framework/Data/ActiveRecord/TActiveRecordGateway.php | 14 +++++++-------
framework/prado-cli.php | 3 +--
tests/simple_unit/ActiveRecord/records/DepSections.php | 2 +-
.../ActiveRecord/records/DepartmentRecord.php | 2 +-
tests/simple_unit/ActiveRecord/records/SimpleUser.php | 2 +-
tests/simple_unit/ActiveRecord/records/SqliteUsers.php | 2 +-
tests/simple_unit/ActiveRecord/records/UserRecord.php | 2 +-
tests/simple_unit/SqlMap/ActiveRecordSqlMapTest.php | 2 +-
21 files changed, 58 insertions(+), 51 deletions(-)
diff --git a/UPGRADE b/UPGRADE
index 9415e94f..9e27ba0b 100644
--- a/UPGRADE
+++ b/UPGRADE
@@ -11,14 +11,22 @@ for both A and B.
Upgrading from v3.1a
---------------------
-- The signature of TActiveRecord::finder() is changed. All TActiveRecord-descendant
- classes that override this method will be affected. Please use the
- following code to override the method:
+- The signature of TActiveRecord::finder() is changed. This affects
+ all TActiveRecord-descendant classes that override this method.
+ Please use the following code to override the method:
public static function finder($className=__CLASS__)
{
return parent::finder($className);
}
+- The way to specify the table name for an active record class is changed.
+ Previously, it used the static class member '_tablename'.
+ Now it uses class constant as follows:
+ class UserRecord extends TActiveRecord
+ {
+ const TABLE='users_table';
+ }
+
Upgrading from v3.0.x
---------------------
- Validators ClientSide.OnSuccess becomes ClientSide.OnValidationSuccess,
diff --git a/demos/address-book/protected/pages/AddressRecord.php b/demos/address-book/protected/pages/AddressRecord.php
index 55c4ba06..aaf8db7c 100644
--- a/demos/address-book/protected/pages/AddressRecord.php
+++ b/demos/address-book/protected/pages/AddressRecord.php
@@ -4,7 +4,7 @@
*/
class AddressRecord extends TActiveRecord
{
- public static $_tablename='addresses';
+ const TABLE='addresses';
/**
* @var integer $id
diff --git a/demos/chat/protected/App_Code/ChatBufferRecord.php b/demos/chat/protected/App_Code/ChatBufferRecord.php
index 03f94704..f4d53db0 100644
--- a/demos/chat/protected/App_Code/ChatBufferRecord.php
+++ b/demos/chat/protected/App_Code/ChatBufferRecord.php
@@ -2,14 +2,14 @@
class ChatBufferRecord extends TActiveRecord
{
+ const TABLE='chat_buffer';
+
public $id;
public $for_user;
public $from_user;
public $message;
private $_created_on;
- public static $_tablename='chat_buffer';
-
public function getCreated_On()
{
if($this->_created_on === null)
diff --git a/demos/chat/protected/App_Code/ChatUserRecord.php b/demos/chat/protected/App_Code/ChatUserRecord.php
index e5ebc761..b68fbd4d 100644
--- a/demos/chat/protected/App_Code/ChatUserRecord.php
+++ b/demos/chat/protected/App_Code/ChatUserRecord.php
@@ -2,11 +2,11 @@
class ChatUserRecord extends TActiveRecord
{
+ const TABLE='chat_users';
+
public $username;
private $_last_activity;
- public static $_tablename='chat_users';
-
public function getLast_Activity()
{
if($this->_last_activity === null)
diff --git a/demos/quickstart/protected/controls/Comments/CommentBlock.php b/demos/quickstart/protected/controls/Comments/CommentBlock.php
index b0f23d47..9c008491 100644
--- a/demos/quickstart/protected/controls/Comments/CommentBlock.php
+++ b/demos/quickstart/protected/controls/Comments/CommentBlock.php
@@ -10,6 +10,8 @@ $manager->setDbConnection($db);
class CommentRecord extends TActiveRecord
{
+ const TABLE='qs_comments';
+
public $id;
public $username;
public $date_added;
@@ -17,8 +19,6 @@ class CommentRecord extends TActiveRecord
public $block_id;
public $content;
- public static $_tablename='qs_comments';
-
public static function finder($className=__CLASS__)
{
return parent::finder($className);
diff --git a/demos/quickstart/protected/pages/Database/ActiveRecord.page b/demos/quickstart/protected/pages/Database/ActiveRecord.page
index 041a1126..0a8d6580 100644
--- a/demos/quickstart/protected/pages/Database/ActiveRecord.page
+++ b/demos/quickstart/protected/pages/Database/ActiveRecord.page
@@ -73,11 +73,11 @@ CREATE TABLE users
Each property of the UserRecord class must correspond to a - column with the same name in the "users" table. The static class variable - $_tablename (must be public) is optional when the class name is the same as - the table name in the database, otherwise $_tablename must + column with the same name in the "users" table. The class constant + TABLE is optional when the class name is the same as + the table name in the database, otherwise TABLE must specify the table name that corresponds to your Active Record class.
@@ -120,7 +120,7 @@ class UserRecord extends TActiveRecord {
* 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 <<