我试图梳理出我遇到的一个逻辑问题,但我不知道还能问哪里!
我有两个我试图描述其关系的对象;User
和Game
。_ 所以,现在,我知道 aUser
属于 many Games
,并且 aGame
属于 many Users
。我要描述的是 aUser
拥有 a时的特殊情况Game
。据推测,这只是表中的一列owner_id
。然而,我正在努力确定如何在 Eloquent 中表达这一点。我需要为游戏所有者创建一个新对象吗?或者我可以使用某种用户角色来描述这一点吗?
游戏
class Game extends Eloquent
{
protected $guarded = array();
public static $rules = array();
// Game belongsToMany User
public function users()
{
return $this->belongsToMany('User');
}
// Need to identify the owner user.
}
用户
class User extends Eloquent
{
protected $guarded = array();
public static $rules = array();
// User belongsToMany Game
public function games()
{
return $this->belongsToMany('Game');
}
}
我什至很难弄清楚如何以清晰简洁的方式提出这个问题,所以如果需要更多细节,请不要犹豫。