提交 15453dbc 编写于 作者: Y yuenblue

aaa

上级 21828e8b
## 环境变量
XDEBUG_CONFIG="idekey=VSCODE"
XDEBUG=vscode
## 快捷键
ctrl/command + shift + k //删除当前行
## cli
php think run
php think make:model
composer create-project topthink/think=~6.0 demotp6
composer create-project topthink/think=~8.0 demotp8
composer create-project topthink/think=~5 demotp5
......
......@@ -7,8 +7,17 @@ use think\Model;
/**
* @mixin \think\Model
* @property string $title
*/
class Article extends Model
{
//
public const Content = 'content';
public function content()
{
return $this->hasOne(ArticleContent::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
}
<?php
declare (strict_types = 1);
namespace app\model;
use think\Model;
/**
* @mixin \think\Model
* @property string $content
*/
class ArticleContent extends Model
{
protected $name='articlecontent';
public function article()
{
return $this->belongsTo(Article::class)->bind(["aaa"=>'content']);
}
}
......@@ -24,5 +24,10 @@ enum UserState:int{
*/
final class User extends Model
{
public const Articles = 'articles';
public function articles()
{
return $this->hasMany(Article::class);
}
}
<?php
use app\model\Article;
use app\model\ArticleContent;
use app\model\User;
use app\model\UserState;
use PHPUnit\Framework\TestCase;
......@@ -19,15 +21,85 @@ class ModelTest extends TestCase
{
assertTrue(true);
}
public function testArticleContentBelongsTo(){
$cc=ArticleContent::find(3);
print $cc->article;
}
public function testhasMany()
{
// $uu = User::find(13);
// foreach ($uu->articles()->where("title","aaaaa")->select() as $item) {
// echo $item->title,PHP_EOL;
// }
// print $uu->articles;
// $user=new User();
// $user->username='aaaa';
// $user->save();
// $aa=new Article();
// $aa->title="aaaaa";
// $bb=new Article();
// $bb->title='bbbbb';
// $user->articles()->saveAll([$aa,$bb]);
$wh=Article::where('user_id','>',0);
$uu = User::with([User::Articles])->hasWhere(User::Articles,$wh)->select();
print $uu;
}
public function testArticleContent()
{
$aa = Article::find(3);
$cc = new ArticleContent();
$cc->content = 'aaaaa';
// $aa->content->content="cccccc";
// $aa->content->save();
// $aa->save();
// $cc->save();
$aa->content()->save($cc);
// $aa->save();
}
public function testArticle()
{
// $aaa=Article::withJoin("content")->select();
// foreach ($aaa as $item) {
// print $item;
// }
// $aa=new Article();
// $aa->title="bbb";
// $aa->save();
$aa = Article::with("content")->find(3);
$aa->content->delete();
$aa->delete();
// print $aa->content->content;
// $aa->content->content = 'cccc';
// $aa->content->save();
// echo $aa->aaa,"???";
// print $aa->content;
}
public function testCreateArticle()
{
$aa = new Article();
$aa->title = "ccc";
$cc=new ArticleContent();
$cc->content='vvvvvv';
$aa->content=$cc;
$aa->together(['content'])->save();
// $aa->save();
}
public function testByName()
{
$user=User::getByUsername('aaa');
$user = User::getByUsername('aaa');
print $user;
}
function testValueColumn()
{
// $res=User::where("id",">",0)->value("email");
$res=User::where("id",">",0)->column("username");
$res = User::where("id", ">", 0)->column("username");
print $res;
}
function testCreate()
......@@ -38,7 +110,6 @@ class ModelTest extends TestCase
$user->password = 'wqsqwsqsw';
$user->status = UserState::Inactive->value;
$user->save();
}
function testSelect()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册