针对关联预载入,多表之间的关联,我想通过实例来给大家展示一下:

    1、三张数据库表:Users表、Profile表、Auth表,其中主表是Users,绑定的两张从表是Profile、Auth

    Users表
    image.png
    Profile表
    image.png

    Auth表
    image.png

    (注意:这里的Users表是主表,Profile表与Auth表是从表,且二者与主表之间都存在关联性,关联外键是Users_id,他们之间被绑定关系,且必须存在关联性)

    Profile模型
    image.png

    Auth()模型
    image.png

    Users模型
    image.png

    Users控制器
    image.png

    输出结果:
    image.png