非单例集合的热切加载
我想加载重复对象的集合。我的模型如下所示:
Item -> Identifier
我想(热切地)加载共享相同标识符的项目集合,但忽略包含一个或更少项目的绝大多数集合。 ORM 关系是双向设置的(Identifier.items 和 Item.identifier)。 SQL 应该看起来像这样:
SELECT * FROM Item WHERE identifier_id IN (
SELECT identifier_id FROM Item GROUP BY identifier_id HAVING COUNT(*) > 1)
I'd like to load collections of repeated objects. My model looks like this:
Item -> Identifier
I'd like to load (eagerly) collections of Items that share the same Identifier, but ignore the vast majority of collections that contain one item or less. The ORM relationship is set up in both directions (Identifier.items and Item.identifier). The SQL should look like something like this:
SELECT * FROM Item WHERE identifier_id IN (
SELECT identifier_id FROM Item GROUP BY identifier_id HAVING COUNT(*) > 1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用子查询,可以通过以下方式实现:
Using a sub-query, this can be achieved as following:
这是我最终使用的版本:(
标识符现在映射到选择,并且不受数据库表支持,这也使得导入速度更快)
Here is the version I am finally using:
(Identifier is now mapped against a select and not backed by a database table, which makes import a bit faster too)