亚洲精品成人_精品成人一区_999视频在线播放_免费黄色在线_亚洲成人久久久_久久www免费视频

一對一關聯 hasOne

定義關聯

定義一對一關聯,例如,每個用戶都有一個個人資料信息,我們定義 User 模型如下:

<?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\UserProfile;

/**
 * @property int    $id
 * @property string $name
 * @property string $email
 */
class User extends AbstractEntity
{
    #[Property(isPrimaryKey: true)]
    public int $id;
    #[Property]
    public ?string $name;
    #[Property]
    public ?string $email;

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

    #[Relate(
        targetEntity: UserProfile::class,
        targetProperty: 'user_id' // 關聯模型的數據表的主鍵
    )]
    public function profile()
    {
        return $this->relateOne();
    }
}

關聯查詢

定義好關聯之后,就可以使用下面的方法獲取關聯數據:

<?php
$user = User::findRecord(1);
// 輸出 UserProfile 關聯模型的email屬性
echo $user->profile()->email;
主站蜘蛛池模板: 毛片入口 | 色老板免费 | 欧美性插视频 | 二级毛片 | 中文字幕在线免费 | 久久99精品久久久久久琪琪 | 成人福利视频在线观看 | 全部黄色软件 | 黄色拍拍视频 | 日本欧美在线观看 | 少妇一级淫片免费放正片 | 91网站在线观看视频 | 久久首页| 色香蕉在线| 一区在线观看视频 | av.com在线| 精品国产青草久久久久福利 | 欧美电影一区 | 欧美精品一区二区在线播放 | 成人毛片在线播放 | 日本欧美国产在线 | 婷婷四房综合激情五月 | 国产黄色大片网站 | 性欢交69精品久久久 | 黄色精品一区二区 | 日韩精品在线一区二区三区 | pt美日韩欧pt网 | 精品欧美久久久 | 无人码一区二区三区视频 | 在线看一级毛片免费视频播放 | 亚洲一级淫片 | 78成人天堂久久成人 | 日本韩国欧美在线 | 四虎精品一区 | 国产精品久久久久久亚洲影视公司 | 天天色天天插 | 亚洲一区 | 亚洲成人91 | 在线免费观看一级片 | 亚州大片 | 操操网av|