多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
>[danger] append() 追加关联属性 + 文章模型 ~~~php <?php namespace app\model; use think\Model; /** * 文章模型 */ class Article extends Model { public function test() { $data = self::with('comments') ->visible(['comments' => ['id', 'aid']]) ->append(['likes.status']) ->select(); dump($data->toArray()); } public function comments() { return $this->hasMany(Comments::class, 'aid'); } public function likes() { return $this->hasMany(Likes::class, 'aid'); } } ~~~ + Likes 模型 ~~~ <?php declare (strict_types = 1); namespace app\model; use think\Model; /** * Likes模型 */ class Likes extends Model { public function getStatusAttr($value) { return 123; } } ~~~ + likes 表没有 status 字段 + 如果关联到数据获取器会自动追加一个属性 ![](https://img.kancloud.cn/bb/99/bb99960bf74aa68423123beedc448afa_477x594.png)