Thinkphp6下两表多个键相互关联

A 表 date mcode

B表 old_date mcode

上面两个表相互关联 A一对多B

Thinkphp6 下需要写成【大道至简 使用where 和$this->键】


public function today()
{
    return $this->hasMany(QuantnModel::class)
        ->where('mcode', $this->mcode)
        ->where('old_date', $this->date);
}

添加索引:

ALTER TABLE cmf_quantn ADD INDEX idx_mcode_old_date (mcode, old_date);

此条目发表在None分类目录。将固定链接加入收藏夹。

发表回复