summaryrefslogtreecommitdiff
path: root/demos/blog-tutorial/samples/day3
diff options
context:
space:
mode:
authorwei <>2007-05-10 23:00:04 +0000
committerwei <>2007-05-10 23:00:04 +0000
commite2cb0b52aaa02a3f3f41d0df377d189529713738 (patch)
treeee4c2a3fece40c9a2d4dde75f6e758f7ef05f8f6 /demos/blog-tutorial/samples/day3
parentef2fc3942664d4d7131542080e838f7754a3081f (diff)
Update blog tutorial
Diffstat (limited to 'demos/blog-tutorial/samples/day3')
-rw-r--r--demos/blog-tutorial/samples/day3/blog/protected/data/blog.dbbin5120 -> 4096 bytes
-rw-r--r--demos/blog-tutorial/samples/day3/blog/protected/database/PostRecord.php23
-rw-r--r--demos/blog-tutorial/samples/day3/blog/protected/database/UserRecord.php23
-rw-r--r--demos/blog-tutorial/samples/day3/blog/protected/schema.sql7
4 files changed, 28 insertions, 25 deletions
diff --git a/demos/blog-tutorial/samples/day3/blog/protected/data/blog.db b/demos/blog-tutorial/samples/day3/blog/protected/data/blog.db
index 37449fd3..fa48526a 100644
--- a/demos/blog-tutorial/samples/day3/blog/protected/data/blog.db
+++ b/demos/blog-tutorial/samples/day3/blog/protected/data/blog.db
Binary files differ
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 a761286a..01f84437 100644
--- a/demos/blog-tutorial/samples/day3/blog/protected/database/PostRecord.php
+++ b/demos/blog-tutorial/samples/day3/blog/protected/database/PostRecord.php
@@ -6,18 +6,19 @@ class PostRecord extends TActiveRecord
{
const TABLE='posts';
- public $post_id;
-
- public $author;
-
- public $create_time;
-
- public $title;
-
- public $content;
-
- public $status;
+ public $post_id;
+ public $author_id;
+ public $create_time;
+ public $title;
+ public $content;
+ public $status;
+ public $author;
+
+ protected static $RELATIONS=array
+ (
+ 'author' => array(self::BELONGS_TO, 'UserRecord'),
+ );
public static function finder($className=__CLASS__)
{
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 87043894..18d5ebbe 100644
--- a/demos/blog-tutorial/samples/day3/blog/protected/database/UserRecord.php
+++ b/demos/blog-tutorial/samples/day3/blog/protected/database/UserRecord.php
@@ -6,18 +6,19 @@ class UserRecord extends TActiveRecord
{
const TABLE='users';
- public $username;
-
- public $email;
-
- public $password;
-
- public $role;
-
- public $first_name;
-
- public $last_name;
+ public $username;
+ public $email;
+ public $password;
+ public $role;
+ public $first_name;
+ public $last_name;
+ public $posts=array();
+
+ protected static $RELATIONS=array
+ (
+ 'posts' => array(self::HAS_MANY, 'PostRecord'),
+ );
public static function finder($className=__CLASS__)
{
diff --git a/demos/blog-tutorial/samples/day3/blog/protected/schema.sql b/demos/blog-tutorial/samples/day3/blog/protected/schema.sql
index d3189b40..89f7388e 100644
--- a/demos/blog-tutorial/samples/day3/blog/protected/schema.sql
+++ b/demos/blog-tutorial/samples/day3/blog/protected/schema.sql
@@ -11,11 +11,12 @@ CREATE TABLE users (
/* create posts table */
CREATE TABLE posts (
post_id INTEGER NOT NULL PRIMARY KEY,
- author VARCHAR(128) NOT NULL, /* references users.username */
+ author_id VARCHAR(128) NOT NULL
+ CONSTRAINT fk_author REFERENCES users(username),
create_time INTEGER NOT NULL, /* UNIX timestamp */
title VARCHAR(256) NOT NULL, /* title of the post */
- content TEXT NOT NULL, /* content of the post */
- status INTEGER NOT NULL /* 0: published; 1: draft; 2: pending; 2: denied */
+ content TEXT, /* post body */
+ status INTEGER NOT NULL /* 0: published; 1: draft; 2: pending; 2: denied */
);
/* insert some initial data records for testing */