2 Star 4 Fork 0

redraiment / phpActiveRecord

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test-join.php 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
redraiment 提交于 2015-07-08 07:37 . 测试数据库
<?php
require_once('activerecord.php');
require_once('unit-test.php');
$db = DB::open('pgsql:host=127.0.0.1;dbname=test;', 'dba', '');
// Tables
$db->dropTable('zombies');
$db->dropTable('tweets');
$db->dropTable('comments');
$Zombie = $db->createTable('zombies',
'name varchar(64)'
);
$Tweet = $db->createTable('tweets',
'zombie_id integer',
'city_id integer',
'content varchar(128)'
);
$Comment = $db->createTable('comments',
'zombie_id integer',
'tweet_id integer',
'content varchar(128)'
);
$Zombie->hasMany('tweets')->by('zombie_id');
$Zombie->hasMany("received_comments")->by("tweet_id")->in("comments")->through("tweets");
$Zombie->hasAndBelongsToMany("commenters")->by("zombie_id")->in("zombies")->be("owner")->through("received_comments");
$Tweet->hasMany("comments")->by("tweet_id");
$ash = $Zombie->create("name:", "Ash");
$bob = $Zombie->create("name:", "Bob");
$jim = $Zombie->create("name:", "Jim");
$ashTweet = $ash->tweets->create("content:", "Hello from Ash");
$ashTweet->comments->create("zombie_id:", $bob->id, "content:", "Cool from Bob");
$ashTweet->comments->create("zombie_id:", $jim->id, "content:", "Cool from Jim");
foreach ($ash->commenters->all() as $commenter) {
echo "{$commenter->id}: {$commenter->name}\n";
}
PHP
1
https://gitee.com/redraiment/phpActiveRecord.git
git@gitee.com:redraiment/phpActiveRecord.git
redraiment
phpActiveRecord
phpActiveRecord
master

搜索帮助