私は3つのテーブルを持っています:
招待、ネスト、およびユーザー。
招待には Nest_id があります。ネストには user_id があります
同じ Nest_id を持つすべてのユーザーを取得したい。これをelequentで行うにはどうすればよいですか?
モデルには has_many 関係があります
私はコントローラでこれをやろうとしています:
$users = User::with('invite')->where('invites.nest_id', '=', $id)->get();
このエラーが発生しています:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'invites.nest_id' in 'where clause'
SQL: SELECT * FROM `users` WHERE `invites`.`nest_id` = ?
Bindings: array (
0 => '2',
)
nest_id 列がないと言っていますが、あります。
class User extends Eloquent
{
public static $table = 'users';
public static $accessible = array('username', 'email', 'picture', 'password');
public function nest()
{
return $this->has_many('Nest');
}
public function invite()
{
return $this->has_many('Invite');
}
class Nest extends Eloquent
{
public static $table = 'nests';
public function user()
{
return $this->belongs_to('User');
}
public function idea()
{
return $this->has_many('Idea');
}
public function invite()
{
return $this->has_many_and_belongs_to('Invite');
}