午夜免费_欧美一级免费看_欧美日韩一区二区视频在线观看_午夜视频在线_日本特黄a级高清免费大片_成年人黄色小视频

一对多关联 hasMany

定义关联

<?php
declare(strict_types=1);

namespace EasySwoole\FastDb\Tests\Model;

use EasySwoole\FastDb\AbstractInterface\AbstractEntity;
use EasySwoole\FastDb\Attributes\Property;
use EasySwoole\FastDb\Attributes\Relate;
use EasySwoole\FastDb\Tests\Model\UserCar;

/**
 * @property int    $id
 * @property string $name
 * @property int    $status
 * @property int    $score
 * @property string $email
 */
class User extends AbstractEntity
{
    #[Property(isPrimaryKey: true)]
    public int $id;
    #[Property]
    public ?string $name;
    #[Property]
    public ?int $status;
    #[Property]
    public ?int $score;
    #[Property]
    public ?int $create_time;
    #[Property]
    public ?string $info;
    #[Property]
    public ?string $foo;
    #[Property]
    public ?string $bar;
    #[Property]
    public ?int $login_time;
    #[Property]
    public ?int $login_times;
    #[Property]
    public ?int $read;
    #[Property]
    public ?string $title;
    #[Property]
    public ?string $content;
    #[Property]
    public ?string $email;

    public function tableName(): string
    {
        return 'easyswoole_user';
    }

    #[Relate(
        targetEntity: UserCar::class,
        targetProperty: 'user_id'
    )]
    public function cars()
    {
        return $this->relateMany();
    }
}

关联查询

<?php
$article = User::findRecord(1);
// 获取用户拥有的所有车辆品牌
$listResult = $article->cars();
foreach ($listResult as $userCar) {
    echo $userCar->car_name . "\n";
}
// or
$objectArr = $listResult->toArray(); // 转换为 对象数组
foreach ($objectArr as $userCar) {
    echo $userCar->car_name . "\n";
}
主站蜘蛛池模板: 日本成人网址 | 中文字幕不卡一区 | 国产精品一区不卡 | 久久九九热 | 91av视频免费观看 | 亚洲一级无毛 | 午夜成年视频 | 国内在线一区 | 亚洲欧洲精品久久 | 99热精品国产 | 久久久久国产成人免费精品免费 | 一本一道久久久a久久久精品蜜臀 | 亚洲综合四区 | 国产欧美亚洲精品 | 91精品久久久久久综合 | 精品天堂 | 一区二区三区久久 | 国产日本欧美一区二区三区 | 国产成人一区在线 | 91麻豆精品国产91久久久资源速度 | 中文字幕第二色 | 国产成人免费在线 | 久久久精品久久 | 国产一二三区在线 | 久久成人精品 | 免费人成网 | 99久久免费看精品国产一区非洲 | 国产福利免费观看 | 91激情| 国产一区二区三区成人久久片老牛 | 国产成人一区二区三区精 | 91成人破解版 | 91免费看片 | 91精品久久久久久久久不卡 | 91免费在线电影 | 91精品国产高清久久久久久 | 一区二区最新免费视频 | 国产欧美日韩三区 | 91精品久久久久久久久入口 | 国产成人啪午夜精品网站男同 | 国产二区在线播放 |