【发布时间】:2017-07-28 09:58:35
【问题描述】:
我有以下工作查询和一个工作正常的子查询我想转换到 Eloquent 因为我想坚持我的用户模型的其他相关性
select * from (
select p.from, a.account_id, count(*) as num
from accounts as a
inner join accounts_prop as p on (a.account_id = p.account_id)
group by p.account_id
having num = 1 ) query
where year(query.von) = 2017
我已经有一个由 (accounts table) 表示的 User 模型和一个由 (properites table) 表示的 Property 模型
User -> Property 关系是一对多
用户
public function properties()
{
return $this->hasMany('App\Property', 'account_id', 'account_id');
}
属性
public function user()
{
return $this->belongsTo('App\User', 'account_id');
}
输出应返回所有拥有一个属性且属性与当前日期匹配的用户。
在用于测试目的的原始查询中,我使用的是常量年份
【问题讨论】:
-
请发布您的表结构并发布您预期的查询输出。