elixir - Ecto query unique through a belongs_to association?
问题描述
I have two models Event
and Customer
. The relationship is that an Event belongs_to
a Customer, which can has_many
Events.
Now, I need to return the count of unique Customers by way of Events, which fall in a particular date range. Does Ecto have any query method that can do what I need?
解决方案
我设法做到了这一点,而不必预先加载或将客户加入事件,因为我可以使用 distinct: event.customer_id
推荐阅读
- c++ - 使用 \n 而不是 endl 和 -std=c++2a 时奇怪的 clangd 崩溃
- c++ - 这个奇怪的 RESEDIT 错误是什么意思,我该如何解决(错误:第 16 行:SUBLANG_NEUTRAL:未声明的标识符)?
- java - java.lang.NullPointerException:尝试调用虚拟方法。请告诉我修复方法,尝试了所有解决方案
- android - 如何在撰写中初始化相机
- javascript - 如何在单击角度 8 中的按钮时从多个下拉列表中删除选定的选项
- node.js - 我可以在 Mongoose 中存储一个包含型号和编号的数组吗?
- terraform-provider-azure - 使用 Terraform 获取 azure Managed Identity ID
- amazon-web-services - 如何将 Cognito 中的用户与他们在 DynamoDB 中的数据联系起来?
- reactjs - React Hook - useState 有延迟时间吗?
- mongodb - mongodb sharding 找不到匹配读取首选项 { 模式:\"primary\" } 的主机