Browse Source

Merge pull request #1852 from creocoder/activerecord-tablename-prefix-fixes

[WIP] ActiveRecord::tableName() hardcoded prefix fix
tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
4bee9e8430
  1. 2
      framework/yii/caching/DbCache.php
  2. 2
      framework/yii/console/controllers/MigrateController.php
  3. 7
      framework/yii/db/ActiveRecord.php
  4. 5
      framework/yii/db/Connection.php
  5. 4
      framework/yii/i18n/DbMessageSource.php
  6. 2
      framework/yii/log/DbTarget.php
  7. 6
      framework/yii/rbac/DbManager.php
  8. 2
      framework/yii/web/DbSession.php

2
framework/yii/caching/DbCache.php

@ -63,7 +63,7 @@ class DbCache extends Cache
* When using DbCache in a production server, we recommend you create a DB index for the 'expire' * When using DbCache in a production server, we recommend you create a DB index for the 'expire'
* column in the cache table to improve the performance. * column in the cache table to improve the performance.
*/ */
public $cacheTable = 'tbl_cache'; public $cacheTable = '{{%cache}}';
/** /**
* @var integer the probability (parts per million) that garbage collection (GC) should be performed * @var integer the probability (parts per million) that garbage collection (GC) should be performed
* when storing a piece of data in the cache. Defaults to 100, meaning 0.01% chance. * when storing a piece of data in the cache. Defaults to 100, meaning 0.01% chance.

2
framework/yii/console/controllers/MigrateController.php

@ -73,7 +73,7 @@ class MigrateController extends Controller
/** /**
* @var string the name of the table for keeping applied migration information. * @var string the name of the table for keeping applied migration information.
*/ */
public $migrationTable = 'tbl_migration'; public $migrationTable = '{{%migration}}';
/** /**
* @var string the template file for generating new migrations. * @var string the template file for generating new migrations.
* This can be either a path alias (e.g. "@app/migrations/template.php") * This can be either a path alias (e.g. "@app/migrations/template.php")

7
framework/yii/db/ActiveRecord.php

@ -177,13 +177,14 @@ class ActiveRecord extends BaseActiveRecord
/** /**
* Declares the name of the database table associated with this AR class. * Declares the name of the database table associated with this AR class.
* By default this method returns the class name as the table name by calling [[Inflector::camel2id()]] * By default this method returns the class name as the table name by calling [[Inflector::camel2id()]]
* with prefix 'tbl_'. For example, 'Customer' becomes 'tbl_customer', and 'OrderItem' becomes * with prefix [[DbConnection::tablePrefix]]. For example if [[DbConnection::tablePrefix]] is 'tbl_',
* 'tbl_order_item'. You may override this method if the table is not named after this convention. * 'Customer' becomes 'tbl_customer', and 'OrderItem' becomes 'tbl_order_item'. You may override this method
* if the table is not named after this convention.
* @return string the table name * @return string the table name
*/ */
public static function tableName() public static function tableName()
{ {
return 'tbl_' . Inflector::camel2id(StringHelper::basename(get_called_class()), '_'); return '{{%' . Inflector::camel2id(StringHelper::basename(get_called_class()), '_') . '}}';
} }
/** /**

5
framework/yii/db/Connection.php

@ -219,10 +219,9 @@ class Connection extends Component
/** /**
* @var string the common prefix or suffix for table names. If a table name is given * @var string the common prefix or suffix for table names. If a table name is given
* as `{{%TableName}}`, then the percentage character `%` will be replaced with this * as `{{%TableName}}`, then the percentage character `%` will be replaced with this
* property value. For example, `{{%post}}` becomes `{{tbl_post}}` if this property is * property value. For example, `{{%post}}` becomes `{{tbl_post}}`.
* set as `"tbl_"`.
*/ */
public $tablePrefix; public $tablePrefix = 'tbl_';
/** /**
* @var array mapping between PDO driver names and [[Schema]] classes. * @var array mapping between PDO driver names and [[Schema]] classes.
* The keys of the array are PDO driver names while the values the corresponding * The keys of the array are PDO driver names while the values the corresponding

4
framework/yii/i18n/DbMessageSource.php

@ -68,11 +68,11 @@ class DbMessageSource extends MessageSource
/** /**
* @var string the name of the source message table. * @var string the name of the source message table.
*/ */
public $sourceMessageTable = 'tbl_source_message'; public $sourceMessageTable = '{{%source_message}}';
/** /**
* @var string the name of the translated message table. * @var string the name of the translated message table.
*/ */
public $messageTable = 'tbl_message'; public $messageTable = '{{%message}}';
/** /**
* @var integer the time in seconds that the messages can remain valid in cache. * @var integer the time in seconds that the messages can remain valid in cache.
* Use 0 to indicate that the cached data will never expire. * Use 0 to indicate that the cached data will never expire.

2
framework/yii/log/DbTarget.php

@ -52,7 +52,7 @@ class DbTarget extends Target
* of some queries about message levels and categories. Depending on your actual needs, you may * of some queries about message levels and categories. Depending on your actual needs, you may
* want to create additional indexes (e.g. index on `log_time`). * want to create additional indexes (e.g. index on `log_time`).
*/ */
public $logTable = 'tbl_log'; public $logTable = '{{%log}}';
/** /**
* Initializes the DbTarget component. * Initializes the DbTarget component.

6
framework/yii/rbac/DbManager.php

@ -41,15 +41,15 @@ class DbManager extends Manager
/** /**
* @var string the name of the table storing authorization items. Defaults to 'tbl_auth_item'. * @var string the name of the table storing authorization items. Defaults to 'tbl_auth_item'.
*/ */
public $itemTable = 'tbl_auth_item'; public $itemTable = '{{%auth_item}}';
/** /**
* @var string the name of the table storing authorization item hierarchy. Defaults to 'tbl_auth_item_child'. * @var string the name of the table storing authorization item hierarchy. Defaults to 'tbl_auth_item_child'.
*/ */
public $itemChildTable = 'tbl_auth_item_child'; public $itemChildTable = '{{%auth_item_child}';
/** /**
* @var string the name of the table storing authorization item assignments. Defaults to 'tbl_auth_assignment'. * @var string the name of the table storing authorization item assignments. Defaults to 'tbl_auth_assignment'.
*/ */
public $assignmentTable = 'tbl_auth_assignment'; public $assignmentTable = '{{%auth_assignment}}';
private $_usingSqlite; private $_usingSqlite;

2
framework/yii/web/DbSession.php

@ -65,7 +65,7 @@ class DbSession extends Session
* When using DbSession in a production server, we recommend you create a DB index for the 'expire' * When using DbSession in a production server, we recommend you create a DB index for the 'expire'
* column in the session table to improve the performance. * column in the session table to improve the performance.
*/ */
public $sessionTable = 'tbl_session'; public $sessionTable = '{{%session}}';
/** /**
* Initializes the DbSession component. * Initializes the DbSession component.

Loading…
Cancel
Save