hasOne(ProductCompatModel::class, 'id', 'compat_id'); } // 按所属产品查询 public function scopeProductId(\think\db\Query $query, int $id) { $query->where('product_id', '=', $id); } }