diff options
author | wei <> | 2007-04-22 00:28:36 +0000 |
---|---|---|
committer | wei <> | 2007-04-22 00:28:36 +0000 |
commit | 38c18b2d740f61e342f00bc33791f0f3c014e126 (patch) | |
tree | 21c12cbd25c7f1ad12d1c7b8dc3ed071a96a2034 /tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php | |
parent | 15fc4fa7120a1795c6112f88145fdfa9bc460455 (diff) |
Update to Active Record to use Mysql 4.
Add TActiveRecordRelation
Diffstat (limited to 'tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php')
-rw-r--r-- | tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php b/tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php new file mode 100644 index 00000000..6c240b2f --- /dev/null +++ b/tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php @@ -0,0 +1,114 @@ +<?php
+
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+
+abstract class Mysql4Record extends TActiveRecord
+{
+ protected static $conn;
+
+ public function getDbConnection()
+ {
+ if(self::$conn===null)
+ self::$conn = new TDbConnection('mysql:host=localhost;port=3306;dbname=tests', 'test4', 'test4');
+ return self::$conn;
+ }
+}
+
+class Album extends Mysql4Record
+{
+ public $title;
+
+ public $Tracks = array(self::HAS_MANY, 'Track');
+ public $Artists = array(self::HAS_MANY, 'Artist', 'album_artist');
+
+ public static function finder($class=__CLASS__)
+ {
+ return parent::finder($class);
+ }
+}
+
+class Artist extends Mysql4Record
+{
+ public $name;
+
+ public $Albums = array(self::HAS_MANY, 'Album', 'album_artist');
+
+ public static function finder($class=__CLASS__)
+ {
+ return parent::finder($class);
+ }
+}
+
+class Track extends Mysql4Record
+{
+ public $id;
+ public $song_name;
+ public $album_id; //FK -> Album.id
+
+ public $Album = array(self::BELONGS_TO, 'Album');
+
+ public static function finder($class=__CLASS__)
+ {
+ return parent::finder($class);
+ }
+}
+
+abstract class SqliteRecord extends TActiveRecord
+{
+ protected static $conn;
+
+ public function getDbConnection()
+ {
+ if(self::$conn===null)
+ self::$conn = new TDbConnection('sqlite:'.dirname(__FILE__).'/blog.db');
+ return self::$conn;
+ }
+}
+
+class PostRecord extends SqliteRecord
+{
+ const TABLE='posts';
+ public $post_id;
+ public $author;
+ public $create_time;
+ public $title;
+ public $content;
+ public $status;
+
+ public $authorRecord = array(self::HAS_ONE, 'BlogUserRecord');
+
+ public static function finder($className=__CLASS__)
+ {
+ return parent::finder($className);
+ }
+}
+class BlogUserRecord extends SqliteRecord
+{
+ const TABLE='users';
+ public $username;
+ public $email;
+ public $password;
+ public $role;
+ public $first_name;
+ public $last_name;
+
+ public $posts = array(self::HAS_MANY, 'PostRecord');
+
+ public static function finder($className=__CLASS__)
+ {
+ return parent::finder($className);
+ }
+}
+
+class ForeignKeyTestCase extends UnitTestCase
+{
+ function test()
+ {
+ $album = Album::finder()->withTracks()->findAll();
+ //print_r($album);
+ //print_r(PostRecord::finder()->findAll());
+ //print_r(BlogUserRecord::finder()->with_posts()->findAll());
+ }
+}
+
+?>
\ No newline at end of file |