summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--HISTORY2
-rw-r--r--framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php1
-rw-r--r--framework/Data/ActiveRecord/TActiveRecordManager.php11
-rw-r--r--framework/Data/ActiveRecord/Vendor/TDbMetaData.php11
-rw-r--r--tests/simple_unit/ActiveRecord/SqliteTestCase.php6
5 files changed, 26 insertions, 5 deletions
diff --git a/HISTORY b/HISTORY
index ab680136..35765681 100644
--- a/HISTORY
+++ b/HISTORY
@@ -21,7 +21,7 @@ ENH: Ticket#482 - ADD TinyMCE 2.0.8 (Wei, TinyMCE 2.1 added)
ENH: Ticket#503 - Localization and parameter tags can now appear as a substring in a property initial value (Qiang)
ENH: Ticket#513 - Display last modified / revision in quickstart (Wei)
ENH: Ticket#519 - Update TActiveRecord implementation (Wei)
-ENH: Ticket#430 - clearing the validator errors (Wei)
+ENH: Ticket#537 - TActiveRecord Pk info ENH [usage: http://trac.pradosoft.com/prado/ticket/537] (Wei)
ENH: Added PRADO_CHMOD constant so that users can specify the permission of PRADO-created directories (Qiang)
ENH: Added Display property to TWebControl (Wei)
ENH: Added TUser.getState() and setState() for storing user session data (Qiang)
diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php
index 4e96a19d..266d4346 100644
--- a/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php
+++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldBase.php
@@ -73,7 +73,6 @@ abstract class TScaffoldBase extends TTemplateControl
*/
protected function getRecordPkValues($record)
{
- $pk = array();
foreach($this->getTableMetaData()->getColumns() as $name=>$column)
{
if($column->getIsPrimaryKey())
diff --git a/framework/Data/ActiveRecord/TActiveRecordManager.php b/framework/Data/ActiveRecord/TActiveRecordManager.php
index f7568b51..0179479e 100644
--- a/framework/Data/ActiveRecord/TActiveRecordManager.php
+++ b/framework/Data/ActiveRecord/TActiveRecordManager.php
@@ -121,6 +121,17 @@ class TActiveRecordManager extends TComponent
}
/**
+ * @param string|TActiveRecord active record class name or instance
+ * @return TDbMetaData record specific meta data
+ */
+ public function getMetaData($record)
+ {
+ if(is_string($record))
+ $record = TActiveRecord::finder($record);
+ return $this->getRecordGateway()->getMetaData($record);
+ }
+
+ /**
* @return TActiveRecordGateway default record gateway.
*/
protected function createRecordGateway()
diff --git a/framework/Data/ActiveRecord/Vendor/TDbMetaData.php b/framework/Data/ActiveRecord/Vendor/TDbMetaData.php
index a3a13120..37537548 100644
--- a/framework/Data/ActiveRecord/Vendor/TDbMetaData.php
+++ b/framework/Data/ActiveRecord/Vendor/TDbMetaData.php
@@ -25,7 +25,12 @@ abstract class TDbMetaData extends TComponent
{
private $_primaryKeys=array();
private $_foreignKeys=array();
- private $_columns=array();
+
+ /**
+ * @var TMap column meta data.
+ */
+ private $_columns;
+
private $_table;
private $_isView=false;
@@ -39,7 +44,7 @@ abstract class TDbMetaData extends TComponent
public function __construct($table, $cols, $pk, $fk=array(),$view=false)
{
$this->_table=$table;
- $this->_columns=$cols;
+ $this->_columns=new TMap($cols);
$this->_primaryKeys=$pk;
$this->_foreignKeys=$fk;
$this->_isView=$view;
@@ -92,7 +97,7 @@ abstract class TDbMetaData extends TComponent
public function getColumnNames()
{
- return array_keys($this->_columns);
+ return $this->_columns->getKeys();
}
/**
diff --git a/tests/simple_unit/ActiveRecord/SqliteTestCase.php b/tests/simple_unit/ActiveRecord/SqliteTestCase.php
index 94af6200..b2d21ef1 100644
--- a/tests/simple_unit/ActiveRecord/SqliteTestCase.php
+++ b/tests/simple_unit/ActiveRecord/SqliteTestCase.php
@@ -16,6 +16,12 @@ class SqliteTestCase extends UnitTestCase
$user = $finder->findByPk('test');
$this->assertNotNull($user);
}
+
+ function test_get_pk()
+ {
+ $meta = TActiveRecordManager::getInstance()->getMetaData('SqliteUsers');
+ $this->assertEqual(array('username'), $meta->PrimaryKeys);
+ }
}
?> \ No newline at end of file