我有3个型号:
客户端,商店,格式
客户有很多商店,商店有一种格式。
所以,我想从客户那里获得所有格式。
In Store table, I have client_id, format_id
in Format table, I have no direct relationship, I have plan_id
In Plan table, I have client_id.
In Client table, I have no useful relationship
我需要获取客户端的所有格式,
所以我需要建立一个关系$ client-> formats
基本上,我想做一个hasManyThrough关系,
class Client extends Model {
protected $table = 'client';
protected $primaryKey = 'clientid';
public function formats()
{
return $this->hasManyThrough(Format::class,Store::class, 'clientid', 'storeid');
}
}
但是我收到了这个错误:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'format.storeid' in 'on clause' (SQL: select `format`.*, `store`.`clientid` from `format` inner join `store` on `store`.`storeid` = `format`.`storeid` where `store`.`clientid` = 58)
我有点陷入这种关系,任何想法如何解决它????