From 4ceba82b9863f2c6323cbe00407e4bfbedbfc1cd Mon Sep 17 00:00:00 2001 From: wei <> Date: Mon, 8 Oct 2007 03:24:07 +0000 Subject: Allow active records to have multiple foreign key references to the same table. Add TXCache. --- .../protected/pages/Database/ActiveRecord.page | 52 ++++++++++++++++----- .../protected/pages/Database/ar_objects.png | Bin 19837 -> 20638 bytes .../protected/pages/Database/ar_objects.vsd | Bin 190976 -> 190976 bytes .../protected/pages/Database/id/ActiveRecord.page | 8 ++-- 4 files changed, 44 insertions(+), 16 deletions(-) (limited to 'demos/quickstart/protected') diff --git a/demos/quickstart/protected/pages/Database/ActiveRecord.page b/demos/quickstart/protected/pages/Database/ActiveRecord.page index a6e087b9..cb10d184 100644 --- a/demos/quickstart/protected/pages/Database/ActiveRecord.page +++ b/demos/quickstart/protected/pages/Database/ActiveRecord.page @@ -657,10 +657,30 @@ in Active Record by inspecting the Players and Teams table def
The "has many" relationship is not fetched automatically when you use any of the Active Record finder methods. @@ -713,7 +733,7 @@ class PlayerRecord extends TActiveRecord public static $RELATIONS=array ( 'team' => array(self::BELONGS_TO, 'TeamRecord'), - 'skills' => array(self::HAS_MANY, 'SkillRecord', 'Player_Skills'), + 'skills' => array(self::MANY_TO_MANY, 'SkillRecord', 'Player_Skills'), 'profile' => array(self::HAS_ONE, 'ProfileRecord'), ); @@ -850,9 +870,9 @@ in the Player_Skills association table using an inner join.
The Prado Active Record design implements the two stage approach. For the -Players-Skills M-N (many-to-many) entity relationship, we need -to define a has many relationship in the PlayerRecord class and -in addition define a has many relationship in the SkillRecord class as well. +Players-Skills M-N (many-to-many) entity relationship, we +define a many-to-many relationship in the PlayerRecord class and +in addition we may define a many-to-many relationship in the SkillRecord class as well. The following sample code defines the complete SkillRecord class with a many-to-many relationship with the PlayerRecord class. (See the PlayerRecord class definition above to the corresponding many-to-many relationship with the SkillRecord class.) @@ -869,7 +889,7 @@ class SkillRecord extends TActiveRecord public static $RELATIONS=array ( - 'players' => array(self::HAS_MANY, 'PlayerRecord', 'Player_Skills'), + 'players' => array(self::MANY_TO_MANY, 'PlayerRecord', 'Player_Skills'), ); public static function finder($className=__CLASS__) @@ -882,12 +902,20 @@ class SkillRecord extends TActiveRecord
The static $RELATIONS property of SkillRecord defines that the property $players has many PlayerRecords via an association table 'Player_Skills'. -In array(self::HAS_MANY, 'PlayerRecord', 'Player_Skills'), the first element defines the -relationship type, in this case self::HAS_MANY, +In array(self::MANY_TO_MANY, 'PlayerRecord', 'Player_Skills'), the first element defines the +relationship type, in this case self::MANY_TO_MANY, the second element is a string 'PlayerRecord' that corresponds to the class name of the PlayerRecord class, and the third element is the name of the association table name.
+ +A list of player objects with the corresponding collection of skill objects may be fetched as follows.
@@ -951,7 +979,7 @@ class Item extends TActiveRecord public static $RELATIONS=array ( - 'related_items' => array(self::HAS_MANY, + 'related_items' => array(self::MANY_TO_MANY, 'Item', 'related_items.related_item_id'), ); } diff --git a/demos/quickstart/protected/pages/Database/ar_objects.png b/demos/quickstart/protected/pages/Database/ar_objects.png index 50ab812d..ac33b88b 100644 Binary files a/demos/quickstart/protected/pages/Database/ar_objects.png and b/demos/quickstart/protected/pages/Database/ar_objects.png differ diff --git a/demos/quickstart/protected/pages/Database/ar_objects.vsd b/demos/quickstart/protected/pages/Database/ar_objects.vsd index 10346c54..d3b3963d 100644 Binary files a/demos/quickstart/protected/pages/Database/ar_objects.vsd and b/demos/quickstart/protected/pages/Database/ar_objects.vsd differ diff --git a/demos/quickstart/protected/pages/Database/id/ActiveRecord.page b/demos/quickstart/protected/pages/Database/id/ActiveRecord.page index b7b9e612..7273640d 100644 --- a/demos/quickstart/protected/pages/Database/id/ActiveRecord.page +++ b/demos/quickstart/protected/pages/Database/id/ActiveRecord.page @@ -615,7 +615,7 @@ class PlayerRecord extends TActiveRecord public static $RELATIONS=array ( 'team' => array(self::BELONGS_TO, 'TeamRecord'), - 'skills' => array(self::HAS_MANY, 'SkillRecord', 'Player_Skills'), + 'skills' => array(self::MANY_TO_MANY, 'SkillRecord', 'Player_Skills'), 'profile' => array(self::HAS_ONE, 'ProfileRecord'), ); @@ -737,7 +737,7 @@ class SkillRecord extends TActiveRecord public static $RELATIONS=array ( - 'players' => array(self::HAS_MANY, 'PlayerRecord', 'Player_Skills'), + 'players' => array(self::MANY_TO_MANY, 'PlayerRecord', 'Player_Skills'), ); public static function finder($className=__CLASS__) @@ -749,7 +749,7 @@ class SkillRecord extends TActiveRecordProperti statis $RELATIONS dari SkillRecord mendefinisikan bahwa properti $players memiliki banyak PlayerRecords melalui tabel asosiasi 'Player_Skills'. -Dalam array(self::HAS_MANY, 'PlayerRecord', 'Player_Skills'), elemen pertama mendefinisikan tipe hubungan, dalam hal ini self::HAS_MANY, +Dalam array(self::MANY_TO_MANY, 'PlayerRecord', 'Player_Skills'), elemen pertama mendefinisikan tipe hubungan, dalam hal ini self::HAS_MANY, elemen kedua adalah string 'PlayerRecord' yang terkait ke nama kelas dari kelas PlayerRecord, dan elemen ketiga adalah nama dari nama tabel asosiasi.
@@ -805,7 +805,7 @@ class Item extends TActiveRecord public static $RELATIONS=array ( - 'related_items' => array(self::HAS_MANY, + 'related_items' => array(self::MANY_TO_MANY, 'Item', 'related_items.related_item_id'), ); } -- cgit v1.2.3