我知道此事已被问过几次,但我仍然坚持下去, 这是我的桌子: 字符:CharacterId,Name 公会:GuildId,姓名 Guild_members:Id,GuildId,CharacterId
我的模特:
公会:
class Guild extends Model { protected $table = "guilds";
public function members()
{
return $this->hasMany('App\Character', 'guild_members', 'CharacterId', 'GuildId');
}
字符:
class Character extends Model { protected $connection = "mysql";
protected $table = "characters";
protected $primaryKey = "Id";
public function Guild()
{
return $this->belongsTo('App\Guild', 'guild_members', 'CharacterId', 'GuildId');
}
当我运行代码时,它给了我:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'guilds.CharacterId' in 'where clause' (SQL: select * from guilds where guilds.CharacterId is null limit 1) (View:
(如果它忽略了字符belongsTo的参数)请帮助,谢谢:)