From 54e9feab491bcf8d1a95b486b68605cb4441e603 Mon Sep 17 00:00:00 2001 From: xue <> Date: Sat, 29 Sep 2007 22:07:12 +0000 Subject: Changed RELATIONS declaration. --- HISTORY | 1 + UPGRADE | 2 ++ demos/blog-tutorial/protected/pages/Day2/CreateAR.page | 4 ++-- demos/blog-tutorial/protected/pages/Day2/fr/CreateAR.page | 4 ++-- demos/blog-tutorial/protected/pages/Day2/id/CreateAR.page | 4 ++-- .../samples/day2/blog/protected/database/PostRecord.php | 2 +- .../samples/day2/blog/protected/database/UserRecord.php | 2 +- .../samples/day3/blog/protected/database/PostRecord.php | 2 +- .../samples/day3/blog/protected/database/UserRecord.php | 2 +- .../samples/day4/blog/protected/database/PostRecord.php | 2 +- .../samples/day4/blog/protected/database/UserRecord.php | 2 +- .../samples/day5/blog/protected/database/PostRecord.php | 2 +- .../samples/day5/blog/protected/database/UserRecord.php | 2 +- demos/northwind-db/protected/database/Category.php | 2 +- demos/northwind-db/protected/database/Customer.php | 2 +- demos/northwind-db/protected/database/Employee.php | 2 +- demos/northwind-db/protected/database/Order.php | 2 +- demos/northwind-db/protected/database/OrderDetail.php | 2 +- demos/northwind-db/protected/database/Product.php | 2 +- demos/northwind-db/protected/database/Region.php | 2 +- demos/northwind-db/protected/database/Shipper.php | 2 +- demos/northwind-db/protected/database/Supplier.php | 2 +- demos/northwind-db/protected/database/Territory.php | 2 +- demos/quickstart/protected/pages/Database/ActiveRecord.page | 12 ++++++------ .../quickstart/protected/pages/Database/id/ActiveRecord.page | 12 ++++++------ .../Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php | 2 +- .../Data/ActiveRecord/Relations/TActiveRecordHasMany.php | 2 +- .../Relations/TActiveRecordHasManyAssociation.php | 4 ++-- .../Data/ActiveRecord/Relations/TActiveRecordHasOne.php | 2 +- .../ActiveRecord/Relations/TActiveRecordRelationContext.php | 6 +----- framework/Data/ActiveRecord/TActiveRecord.php | 10 ++++++++++ tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php | 6 +++--- tests/simple_unit/ActiveRecord/ForeignObjectUpdateTest.php | 8 ++++---- tests/simple_unit/ActiveRecord/records/ItemRecord.php | 2 +- 34 files changed, 63 insertions(+), 54 deletions(-) diff --git a/HISTORY b/HISTORY index 2448081a..964781f3 100644 --- a/HISTORY +++ b/HISTORY @@ -28,6 +28,7 @@ ENH: Added prompt text support to TDropDownList and TListBox (Qiang) CHG: Ticket#685 - Slashes and backslashes mixup in PradoBase (Qiang) CHG: Ticket#705 - TImage will not set border style by default (Qiang) CHG: GeSHi is replaced with Text_Highlighter (Christophe) +CHG: Changed the way to declare relationships in Active Record (Qiang) CHG: Validators will not validate disabled controls (Qiang) NEW: Ticket#676 - Added primilary Oracle support (Christophe) NEW: Ticket#680 - Added TCacheHttpSession (Carl, Qiang) diff --git a/UPGRADE b/UPGRADE index 3388dd3c..b96ce565 100644 --- a/UPGRADE +++ b/UPGRADE @@ -11,6 +11,8 @@ for both A and B. Upgrading from v3.1.0 --------------------- +- The RELATIONS declaration in Acive Record classes is changed from + "protected static $RELATIONS" to "public static $RELATIONS". - IFeedContentProvider adds a new method: getContentType(). This affects any class implementing this interface. - TUrlMapping now only uses the PATH_INFO part of URL for matching, and the matching diff --git a/demos/blog-tutorial/protected/pages/Day2/CreateAR.page b/demos/blog-tutorial/protected/pages/Day2/CreateAR.page index 381e2469..1d7838a2 100644 --- a/demos/blog-tutorial/protected/pages/Day2/CreateAR.page +++ b/demos/blog-tutorial/protected/pages/Day2/CreateAR.page @@ -134,7 +134,7 @@ class PostRecord extends TActiveRecord public $author; //holds an UserRecord - protected static $RELATIONS=array + public static $RELATIONS=array ( 'author' => array(self::BELONGS_TO, 'UserRecord'), ); @@ -152,7 +152,7 @@ class UserRecord extends TActiveRecord public $posts=array(); //holds an array of PostRecord - protected static $RELATIONS=array + public static $RELATIONS=array ( 'posts' => array(self::HAS_MANY, 'PostRecord'), ); diff --git a/demos/blog-tutorial/protected/pages/Day2/fr/CreateAR.page b/demos/blog-tutorial/protected/pages/Day2/fr/CreateAR.page index 82c1dbf8..1c5aae7b 100755 --- a/demos/blog-tutorial/protected/pages/Day2/fr/CreateAR.page +++ b/demos/blog-tutorial/protected/pages/Day2/fr/CreateAR.page @@ -133,7 +133,7 @@ class PostRecord extends TActiveRecord public $author; //contient un objet UserRecord - protected static $RELATIONS=array + public static $RELATIONS=array ( 'author' => array(self::BELONGS_TO, 'UserRecord'), ); @@ -151,7 +151,7 @@ class UserRecord extends TActiveRecord public $posts=array(); //contient un tableau de PostRecord - protected static $RELATIONS=array + public static $RELATIONS=array ( 'posts' => array(self::HAS_MANY, 'PostRecord'), ); diff --git a/demos/blog-tutorial/protected/pages/Day2/id/CreateAR.page b/demos/blog-tutorial/protected/pages/Day2/id/CreateAR.page index 533825c6..0d4b178d 100644 --- a/demos/blog-tutorial/protected/pages/Day2/id/CreateAR.page +++ b/demos/blog-tutorial/protected/pages/Day2/id/CreateAR.page @@ -134,7 +134,7 @@ class PostRecord extends TActiveRecord public $author; //menampung array UserRecord - protected static $RELATIONS=array + public static $RELATIONS=array ( 'author' => array(self::BELONGS_TO, 'UserRecord'), ); @@ -152,7 +152,7 @@ class UserRecord extends TActiveRecord public $posts=array(); //menampung array PostRecord - protected static $RELATIONS=array + public static $RELATIONS=array ( 'posts' => array(self::HAS_MANY, 'PostRecord'), ); diff --git a/demos/blog-tutorial/samples/day2/blog/protected/database/PostRecord.php b/demos/blog-tutorial/samples/day2/blog/protected/database/PostRecord.php index 01f84437..25702727 100644 --- a/demos/blog-tutorial/samples/day2/blog/protected/database/PostRecord.php +++ b/demos/blog-tutorial/samples/day2/blog/protected/database/PostRecord.php @@ -15,7 +15,7 @@ class PostRecord extends TActiveRecord public $author; - protected static $RELATIONS=array + public static $RELATIONS=array ( 'author' => array(self::BELONGS_TO, 'UserRecord'), ); diff --git a/demos/blog-tutorial/samples/day2/blog/protected/database/UserRecord.php b/demos/blog-tutorial/samples/day2/blog/protected/database/UserRecord.php index 18d5ebbe..2051e5de 100644 --- a/demos/blog-tutorial/samples/day2/blog/protected/database/UserRecord.php +++ b/demos/blog-tutorial/samples/day2/blog/protected/database/UserRecord.php @@ -15,7 +15,7 @@ class UserRecord extends TActiveRecord public $posts=array(); - protected static $RELATIONS=array + public static $RELATIONS=array ( 'posts' => array(self::HAS_MANY, 'PostRecord'), ); diff --git a/demos/blog-tutorial/samples/day3/blog/protected/database/PostRecord.php b/demos/blog-tutorial/samples/day3/blog/protected/database/PostRecord.php index 01f84437..25702727 100644 --- a/demos/blog-tutorial/samples/day3/blog/protected/database/PostRecord.php +++ b/demos/blog-tutorial/samples/day3/blog/protected/database/PostRecord.php @@ -15,7 +15,7 @@ class PostRecord extends TActiveRecord public $author; - protected static $RELATIONS=array + public static $RELATIONS=array ( 'author' => array(self::BELONGS_TO, 'UserRecord'), ); diff --git a/demos/blog-tutorial/samples/day3/blog/protected/database/UserRecord.php b/demos/blog-tutorial/samples/day3/blog/protected/database/UserRecord.php index 18d5ebbe..2051e5de 100644 --- a/demos/blog-tutorial/samples/day3/blog/protected/database/UserRecord.php +++ b/demos/blog-tutorial/samples/day3/blog/protected/database/UserRecord.php @@ -15,7 +15,7 @@ class UserRecord extends TActiveRecord public $posts=array(); - protected static $RELATIONS=array + public static $RELATIONS=array ( 'posts' => array(self::HAS_MANY, 'PostRecord'), ); diff --git a/demos/blog-tutorial/samples/day4/blog/protected/database/PostRecord.php b/demos/blog-tutorial/samples/day4/blog/protected/database/PostRecord.php index 01f84437..25702727 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/database/PostRecord.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/database/PostRecord.php @@ -15,7 +15,7 @@ class PostRecord extends TActiveRecord public $author; - protected static $RELATIONS=array + public static $RELATIONS=array ( 'author' => array(self::BELONGS_TO, 'UserRecord'), ); diff --git a/demos/blog-tutorial/samples/day4/blog/protected/database/UserRecord.php b/demos/blog-tutorial/samples/day4/blog/protected/database/UserRecord.php index 18d5ebbe..2051e5de 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/database/UserRecord.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/database/UserRecord.php @@ -15,7 +15,7 @@ class UserRecord extends TActiveRecord public $posts=array(); - protected static $RELATIONS=array + public static $RELATIONS=array ( 'posts' => array(self::HAS_MANY, 'PostRecord'), ); diff --git a/demos/blog-tutorial/samples/day5/blog/protected/database/PostRecord.php b/demos/blog-tutorial/samples/day5/blog/protected/database/PostRecord.php index 01f84437..25702727 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/database/PostRecord.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/database/PostRecord.php @@ -15,7 +15,7 @@ class PostRecord extends TActiveRecord public $author; - protected static $RELATIONS=array + public static $RELATIONS=array ( 'author' => array(self::BELONGS_TO, 'UserRecord'), ); diff --git a/demos/blog-tutorial/samples/day5/blog/protected/database/UserRecord.php b/demos/blog-tutorial/samples/day5/blog/protected/database/UserRecord.php index 18d5ebbe..2051e5de 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/database/UserRecord.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/database/UserRecord.php @@ -15,7 +15,7 @@ class UserRecord extends TActiveRecord public $posts=array(); - protected static $RELATIONS=array + public static $RELATIONS=array ( 'posts' => array(self::HAS_MANY, 'PostRecord'), ); diff --git a/demos/northwind-db/protected/database/Category.php b/demos/northwind-db/protected/database/Category.php index 05fa7ed0..06fc979f 100644 --- a/demos/northwind-db/protected/database/Category.php +++ b/demos/northwind-db/protected/database/Category.php @@ -13,7 +13,7 @@ class Category extends TActiveRecord public $Products=array(); - protected static $RELATIONS=array + public static $RELATIONS=array ( 'Products' => array(self::HAS_MANY, 'Product'), ); diff --git a/demos/northwind-db/protected/database/Customer.php b/demos/northwind-db/protected/database/Customer.php index 356dd02f..810f2a6a 100644 --- a/demos/northwind-db/protected/database/Customer.php +++ b/demos/northwind-db/protected/database/Customer.php @@ -20,7 +20,7 @@ class Customer extends TActiveRecord public $Orders=array(); - protected static $RELATIONS = array + public static $RELATIONS = array ( 'Orders' => array(self::HAS_MANY, 'Order'), ); diff --git a/demos/northwind-db/protected/database/Employee.php b/demos/northwind-db/protected/database/Employee.php index 7a678f57..92de3f24 100644 --- a/demos/northwind-db/protected/database/Employee.php +++ b/demos/northwind-db/protected/database/Employee.php @@ -30,7 +30,7 @@ class Employee extends TActiveRecord public $Subordinates=array(); public $Superior; - protected static $RELATIONS = array + public static $RELATIONS = array ( 'Territories' => array(self::HAS_MANY, 'Territory', 'EmployeeTerritories'), 'Orders' => array(self::HAS_MANY, 'Order'), diff --git a/demos/northwind-db/protected/database/Order.php b/demos/northwind-db/protected/database/Order.php index fa865e61..228fb2b5 100644 --- a/demos/northwind-db/protected/database/Order.php +++ b/demos/northwind-db/protected/database/Order.php @@ -26,7 +26,7 @@ class Order extends TActiveRecord public $Shipper; public $Employee; - protected static $RELATIONS = array + public static $RELATIONS = array ( 'OrderDetails' => array(self::HAS_MANY, 'OrderDetail'), 'Customer' => array(self::BELONGS_TO, 'Customer'), diff --git a/demos/northwind-db/protected/database/OrderDetail.php b/demos/northwind-db/protected/database/OrderDetail.php index 9415e33e..1732b0d9 100644 --- a/demos/northwind-db/protected/database/OrderDetail.php +++ b/demos/northwind-db/protected/database/OrderDetail.php @@ -13,7 +13,7 @@ class OrderDetail extends TActiveRecord public $Product; public $Order; - protected static $RELATIONS = array + public static $RELATIONS = array ( 'Product' => array(self::BELONGS_TO, 'Product'), 'Order' => array(self::BELONGS_TO, 'Order'), diff --git a/demos/northwind-db/protected/database/Product.php b/demos/northwind-db/protected/database/Product.php index 75d01c02..93736ab8 100644 --- a/demos/northwind-db/protected/database/Product.php +++ b/demos/northwind-db/protected/database/Product.php @@ -21,7 +21,7 @@ class Product extends TActiveRecord public $Category; public $OrderDetails=array(); - protected static $RELATIONS = array + public static $RELATIONS = array ( 'Supplier' => array(self::BELONGS_TO, 'Supplier'), 'Category' => array(self::BELONGS_TO, 'Category'), diff --git a/demos/northwind-db/protected/database/Region.php b/demos/northwind-db/protected/database/Region.php index 2afa3501..c6e23485 100644 --- a/demos/northwind-db/protected/database/Region.php +++ b/demos/northwind-db/protected/database/Region.php @@ -11,7 +11,7 @@ class Region extends TActiveRecord public $Territories=array(); - protected static $RELATIONS = array + public static $RELATIONS = array ( 'Territories' => array(self::HAS_MANY, 'Territory') ); diff --git a/demos/northwind-db/protected/database/Shipper.php b/demos/northwind-db/protected/database/Shipper.php index 6ac8a929..a3f0aeb3 100644 --- a/demos/northwind-db/protected/database/Shipper.php +++ b/demos/northwind-db/protected/database/Shipper.php @@ -12,7 +12,7 @@ class Shipper extends TActiveRecord public $Orders = array(); - protected static $RELATIONS = array + public static $RELATIONS = array ( 'Orders' => array(self::HAS_MANY, 'Order'), ); diff --git a/demos/northwind-db/protected/database/Supplier.php b/demos/northwind-db/protected/database/Supplier.php index 537daade..7cabdde5 100644 --- a/demos/northwind-db/protected/database/Supplier.php +++ b/demos/northwind-db/protected/database/Supplier.php @@ -21,7 +21,7 @@ class Supplier extends TActiveRecord public $Products=array(); - protected static $RELATIONS=array + public static $RELATIONS=array ( 'Products' => array(self::HAS_MANY, 'Product') ); diff --git a/demos/northwind-db/protected/database/Territory.php b/demos/northwind-db/protected/database/Territory.php index 4da0ff46..16f33dea 100644 --- a/demos/northwind-db/protected/database/Territory.php +++ b/demos/northwind-db/protected/database/Territory.php @@ -13,7 +13,7 @@ class Territory extends TActiveRecord private $_region; private $_employees; - protected static $RELATIONS = array + public static $RELATIONS = array ( 'Region' => array(self::BELONGS_TO, 'Region'), 'Employees' => array(self::HAS_MANY, 'Employee', 'EmployeeTerritories') diff --git a/demos/quickstart/protected/pages/Database/ActiveRecord.page b/demos/quickstart/protected/pages/Database/ActiveRecord.page index ce92f489..a6e087b9 100644 --- a/demos/quickstart/protected/pages/Database/ActiveRecord.page +++ b/demos/quickstart/protected/pages/Database/ActiveRecord.page @@ -627,7 +627,7 @@ class TeamRecord extends TActiveRecord public $players=array(); //define the $player member having has many relationship with PlayerRecord - protected static $RELATIONS=array + public static $RELATIONS=array ( 'players' => array(self::HAS_MANY, 'PlayerRecord'), ); @@ -710,7 +710,7 @@ class PlayerRecord extends TActiveRecord public $skills=array(); public $profile; - protected static $RELATIONS=array + public static $RELATIONS=array ( 'team' => array(self::BELONGS_TO, 'TeamRecord'), 'skills' => array(self::HAS_MANY, 'SkillRecord', 'Player_Skills'), @@ -767,7 +767,7 @@ class ProfileRecord extends TActiveRecord public $player; - protected static $RELATIONS=array + public static $RELATIONS=array ( 'player' => array(self::BELONGS_TO, 'PlayerRecord'), ); @@ -813,7 +813,7 @@ class Category extends TActiveRecord public $parent_category; public $child_categories=array(); - protected static $RELATIONS=array + public static $RELATIONS=array ( 'parent_category' => array(self::BELONGS_TO, 'Category'), 'child_categories' => array(self::HAS_MANY, 'Category'), @@ -867,7 +867,7 @@ class SkillRecord extends TActiveRecord public $players=array(); - protected static $RELATIONS=array + public static $RELATIONS=array ( 'players' => array(self::HAS_MANY, 'PlayerRecord', 'Player_Skills'), ); @@ -949,7 +949,7 @@ class Item extends TActiveRecord public $related_item_id; public $related_items=array(); - protected static $RELATIONS=array + public static $RELATIONS=array ( 'related_items' => array(self::HAS_MANY, 'Item', 'related_items.related_item_id'), diff --git a/demos/quickstart/protected/pages/Database/id/ActiveRecord.page b/demos/quickstart/protected/pages/Database/id/ActiveRecord.page index d4e473d8..b7b9e612 100644 --- a/demos/quickstart/protected/pages/Database/id/ActiveRecord.page +++ b/demos/quickstart/protected/pages/Database/id/ActiveRecord.page @@ -552,7 +552,7 @@ class TeamRecord extends TActiveRecord public $players=array(); //mendefinisikan anggota $player yang memiliki hubungan banyak dengan PlayerRecord - protected static $RELATIONS=array + public static $RELATIONS=array ( 'players' => array(self::HAS_MANY, 'PlayerRecord'), ); @@ -612,7 +612,7 @@ class PlayerRecord extends TActiveRecord public $skills=array(); public $profile; - protected static $RELATIONS=array + public static $RELATIONS=array ( 'team' => array(self::BELONGS_TO, 'TeamRecord'), 'skills' => array(self::HAS_MANY, 'SkillRecord', 'Player_Skills'), @@ -658,7 +658,7 @@ class ProfileRecord extends TActiveRecord public $player; - protected static $RELATIONS=array + public static $RELATIONS=array ( 'player' => array(self::BELONGS_TO, 'PlayerRecord'), ); @@ -698,7 +698,7 @@ class Category extends TActiveRecord public $parent_category; public $child_categories=array(); - protected static $RELATIONS=array + public static $RELATIONS=array ( 'parent_category' => array(self::BELONGS_TO, 'Category'), 'child_categories' => array(self::HAS_MANY, 'Category'), @@ -735,7 +735,7 @@ class SkillRecord extends TActiveRecord public $players=array(); - protected static $RELATIONS=array + public static $RELATIONS=array ( 'players' => array(self::HAS_MANY, 'PlayerRecord', 'Player_Skills'), ); @@ -803,7 +803,7 @@ class Item extends TActiveRecord public $related_item_id; public $related_items=array(); - protected static $RELATIONS=array + public static $RELATIONS=array ( 'related_items' => array(self::HAS_MANY, 'Item', 'related_items.related_item_id'), diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php b/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php index 02d0b0e3..5d20476c 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php @@ -39,7 +39,7 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); * public $age; * public $team; //foreign object TeamRecord * - * protected static $RELATIONS = array + * public static $RELATIONS = array * ( * 'team' => array(self::BELONGS_TO, 'TeamRecord') * ); diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php b/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php index 5c180c12..fea78e36 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php @@ -34,7 +34,7 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); * * public $players=array(); //list of players * - * protected static $RELATIONS=array + * public static $RELATIONS=array * ( * 'players' => array(self::HAS_MANY, 'PlayerRecord') * ); diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php b/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php index 65989639..7e942e67 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php @@ -35,7 +35,7 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); * * public $Categories=array(); //foreign object collection. * - * protected static $RELATIONS = array + * public static $RELATIONS = array * ( * 'Categories' => array(self::HAS_MANY, 'CategoryRecord', 'Article_Category') * ); @@ -52,7 +52,7 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); * * public $Articles=array(); * - * protected static $RELATIONS = array + * public static $RELATIONS = array * ( * 'Articles' => array(self::HAS_MANY, 'ArticleRecord', 'Article_Category') * ); diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php b/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php index 7127d2ac..375c38ef 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php @@ -43,7 +43,7 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); * * public $engine; //engine foreign object * - * protected static $RELATIONS=array + * public static $RELATIONS=array * ( * 'engine' => array(self::HAS_ONE, 'EngineRecord') * ); diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php b/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php index 16b29861..c9b47d12 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php @@ -68,11 +68,7 @@ class TActiveRecordRelationContext public function getRecordRelationships() { $class = new ReflectionClass($this->_sourceRecord); - $statics = $class->getStaticProperties(); - if(isset($statics[self::RELATIONS_CONST])) - return $statics[self::RELATIONS_CONST]; - else - return array(); + return $class->getStaticPropertyValue(self::RELATIONS_CONST); } public function getPropertyValue() diff --git a/framework/Data/ActiveRecord/TActiveRecord.php b/framework/Data/ActiveRecord/TActiveRecord.php index 5cc6dee0..bf7b68d9 100644 --- a/framework/Data/ActiveRecord/TActiveRecord.php +++ b/framework/Data/ActiveRecord/TActiveRecord.php @@ -106,9 +106,19 @@ abstract class TActiveRecord extends TComponent * and the values are logical column names as defined as public variable/property names * for the corresponding active record class. * @var array column mapping. Keys: physical column names, values: logical column names. + * @since 3.1.1 */ public static $COLUMN_MAPPING=array(); + /** + * This static variable defines the relationships. + * The keys are public variable/property names defined in the AR class. + * Each value is an array, e.g. array(self::HAS_MANY, 'PlayerRecord'). + * @var array relationship. + * @since 3.1.1 + */ + public static $RELATIONS=array(); + /** * @var boolean true if this class is read only. */ diff --git a/tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php b/tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php index 0c1da5d2..cbde7fa0 100644 --- a/tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php +++ b/tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php @@ -24,7 +24,7 @@ class Album extends SqliteRecord public $cover; - protected static $RELATIONS = array( + public static $RELATIONS = array( 'Tracks' => array(self::HAS_MANY, 'Track'), 'Artists' => array(self::HAS_MANY, 'Artist', 'album_artists'), 'cover' => array(self::HAS_ONE, 'Cover') @@ -42,7 +42,7 @@ class Artist extends SqliteRecord public $Albums = array(); - protected static $RELATIONS=array( + public static $RELATIONS=array( 'Albums' => array(self::HAS_MANY, 'Album', 'album_artists') ); @@ -60,7 +60,7 @@ class Track extends SqliteRecord public $Album; - protected static $RELATIONS = array( + public static $RELATIONS = array( 'Album' => array(self::BELONGS_TO, 'Album'), ); diff --git a/tests/simple_unit/ActiveRecord/ForeignObjectUpdateTest.php b/tests/simple_unit/ActiveRecord/ForeignObjectUpdateTest.php index ad64e4b6..36864f77 100644 --- a/tests/simple_unit/ActiveRecord/ForeignObjectUpdateTest.php +++ b/tests/simple_unit/ActiveRecord/ForeignObjectUpdateTest.php @@ -28,7 +28,7 @@ class TeamRecord extends BaseFkRecord public $players=array(); //define the $player member having has many relationship with PlayerRecord - protected static $RELATIONS=array + public static $RELATIONS=array ( 'players' => array(self::HAS_MANY, 'PlayerRecord'), ); @@ -50,7 +50,7 @@ class PlayerRecord extends BaseFkRecord private $_skills; public $profile; - protected static $RELATIONS=array + public static $RELATIONS=array ( 'skills' => array(self::HAS_MANY, 'SkillRecord', 'player_skills'), 'team' => array(self::BELONGS_TO, 'TeamRecord'), @@ -91,7 +91,7 @@ class ProfileRecord extends BaseFkRecord public $player; - protected static $RELATIONS=array + public static $RELATIONS=array ( 'player' => array(self::BELONGS_TO, 'PlayerRecord'), ); @@ -110,7 +110,7 @@ class SkillRecord extends BaseFkRecord public $players=array(); - protected static $RELATIONS=array + public static $RELATIONS=array ( 'players' => array(self::HAS_MANY, 'PlayerRecord', 'player_skills'), ); diff --git a/tests/simple_unit/ActiveRecord/records/ItemRecord.php b/tests/simple_unit/ActiveRecord/records/ItemRecord.php index 189d22c9..45d15427 100644 --- a/tests/simple_unit/ActiveRecord/records/ItemRecord.php +++ b/tests/simple_unit/ActiveRecord/records/ItemRecord.php @@ -19,7 +19,7 @@ class ItemRecord extends TActiveRecord public $related_items = array(); public $related_item_id; - protected static $RELATIONS=array + public static $RELATIONS=array ( 'related_items' => array(self::HAS_MANY, 'ItemRecord', 'related_items.(related_item_id)'), ); -- cgit v1.2.3