Search code examples
elixirecto

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?


Solution

  • I managed to do this without having to preload or join the Customer to Events, since I could use distinct: event.customer_id