Laravel很多人没有使用id列

时间:2016-08-29 22:55:23

标签: php mysql laravel laravel-5.3

我有3张桌子。玩家,玩家技能和技能。

Players
- bb1_player_id

Skills
- bb1_skill_id

Player_skills
- bb1_player_id
- bb1_skill_id

我用这种方法创建了玩家模型。

public function skills()
{
    return $this->belongsToMany('App\Skills', 'player_skills', 'bb1_player_id', 'bb1_skill_id');
}

输出此查询:

"select `skills`.*, `player_skills`.`bb1_player_id` as `pivot_bb1_player_id`, `player_skills`.`bb1_skill_id` as `pivot_bb1_skill_id` from `skills` inner join `player_skills` on `skills`.`id` = `player_skills`.`bb1_skill_id` where `player_skills`.`bb1_player_id` = ?"

查询有效,但我希望得到的查询并非每次都使用表的id字段,而只使用我指定的字段。它使用技能的id和'?'的player.id的查询。有没有解决的办法?或者我是否需要重新修改表格以符合要求?

我也试过添加更多选项,如下所示无济于事。

public function skills()
{
    return $this->belongsToMany('App\Skills', 'player_skills','bb1_player_id','bb1_skill_id','bb1_player_id','bb1_skill_id');
}

0 个答案:

没有答案