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);