【发布时间】:2014-09-23 07:56:46
【问题描述】:
我正在尝试编写一个表达式,它应该给我所有“剪辑”,其中currentUserId 是creator,或者clip 是sharedWith 给定的currentUserId。
creator 是一对多的(一个创作者可以有很多剪辑),sharedWith 是多对多的(许多clips 可以与许多用户共享):
Clip.find.where().or(
eq("creator.id", currentUserId),
eq("sharedWith.id", currentUserId)
);
上面只返回与currentUserId共享剪辑的剪辑,因此省略了OR。
我尝试使用 Junctions:
Clip.find.where().disjunction()
.add(eq("creator.id", currentUserId))
.add(eq("sharedWith.id", currentUserId)).endJunction();
它返回相同的结果。
如果有任何问题,我正在使用 Play Framework 2。
我宁愿避免使用 RawSql,因为这些不是唯一添加的表达式(但是我确实删除了其他表达式以查看它是否有效,因此它没有相关性)。
编辑:
我编写了应该返回正确结果的查询:
select * from clip
join user u on (clip.creator_id = u.id)
left outer join user_clip uc on (clip.id = uc.clip_id)
where (u.id = 1) or (uc.user_id = 1)
如何让 Ebean 为我生成这个?
【问题讨论】:
标签: java mysql playframework ebean