From 38c18b2d740f61e342f00bc33791f0f3c014e126 Mon Sep 17 00:00:00 2001 From: wei <> Date: Sun, 22 Apr 2007 00:28:36 +0000 Subject: Update to Active Record to use Mysql 4. Add TActiveRecordRelation --- .../ActiveRecord/ForeignKeyTestCase.php | 114 +++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php (limited to 'tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php') 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 @@ + 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 -- cgit v1.2.3