【发布时间】:2014-11-23 13:47:54
【问题描述】:
在经典的 Rest API 方法中,我的应用程序需要检查用户是否与某个帐户相关。我们可以对多个帐户执行操作,因此查询会针对每个请求执行。 因为这是我们最常调用的查询,所以它的轻便性对我的安心很重要。
当前查询,使用 Eloquent
$user-> accounts()-> where($primaryKey, $id);
不知何故,这些都会产生错误(Eloquent 错误?)
$user-> accounts()-> find ($id);
$user-> accounts()-> where ($primaryKey, $id)->count();
错误:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'a_id' in where clause is ambiguous (SQL: select * from 'accounts' inner join 'users_accounts' on 'accounts'.'a_id' = 'users_accounts'.'a_id' where 'users_accounts'.'u_id' = 1 and 'a_id' = 1 limit 1)
回到我的问题,有没有比“where”函数更优雅的解决方案?
【问题讨论】:
标签: php mysql laravel eloquent relationship