简体   繁体   English

从Korma中的表中选择无字段

[英]Select no fields from table in Korma

I'm trying to do a join across a number of tables (three plus a join table in the middle). 我正在尝试跨多个表(三个加上中间的连接表)进行连接。 I think korma is lazily evaluating the last join. 我认为korma懒惰地评估最后一次加入。 What I'm trying to do is to add a condition that restricts the results of the first table in the join, but I'm only interested in fields from the last table in the join. 我要做的是添加一个限制连接中第一个表的结果的条件,但我只对连接中最后一个表的字段感兴趣。

So for example say I've got clubs , people and hobbies tables, and a people-to-hobbies join table for the last two. 因此,例如说我有clubspeoplehobbies表,以及people-to-hobbies连接表在过去两年。 Each club can have many people, and each person can have many hobbies. 每个俱乐部都可以有很多人,每个人都可以有很多爱好。

I'm trying to get the full details of all the hobbies of people who belong to a specific club, but I don't want any fields from the club table. 我正在努力获得属于特定俱乐部的人的所有爱好的全部细节,但我不想要club桌上的任何领域。 The join table means that korma will create two queries, one to get all the people that are in a specific club, and another to retrieve the hobbies for that person via the people-to-hobbies join table. 联接表意味着korma将创建两个查询,一个用于获取特定俱乐部中的所有人,另一个用于通过people-to-hobbies连接表检索该人people-to-hobbies

My korma query looks something like this: 我的korma查询看起来像这样:

(select clubs
  (with people
    (with hobbies
      (fields :hobby-name :id)
      (where {:clubs.name "korma coders"}))))

The problem is that I haven't specified which fields I want from clubs and people , and the default is to select * . 问题是我没有指定我想从clubspeople哪些字段,默认是选择* How can I include no fields from these tables? 如何从这些表中不包含任何字段? Is this possible, or does the fact that the hobbies are lazily loaded mean korma has to return some results in the first query (which gets me a filtered list of people), so that when I come to interrogate it later for the hobbies, it has the ids it needs to run the second query? 这是可能的,还是hobbies是懒惰的,这意味着korma必须在第一个查询中返回一些结果(这会让我得到一个过滤的人员列表),所以当我后来为了兴趣而来询问它时,它有运行第二个查询所需的ID吗?

I'd use join macro in such case: 在这种情况下我会使用join宏:

(select clubs
  (join people)
  (join people-to-hobbies)
  (join hobbies)
  (fields :hobbies.hobby-name :hobbies.id)
  (where {:clubs.name "korma coders"}))))

It's a bit more explicit, but as an additional benefit it's run with a single query. 它更加明确,但作为额外的好处,它可以通过单个查询运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM