Hoe to join where clauses in Ecto?

Hi! I think this is an easy question, I just can’t find an example.

I’ve looked at the examples for where and or_where and couldn’t figure it out from there.

Say you have a doggy daycare database that has a daycare table and a dog table. You’re doing a basic text search that covers a few fields, and it scopes to a specific daycare.

So say you want to get all dogs from a daycare of id 5 whose name or color has the word “brown”. The SQL looks like this, and works great:

select * from dogs where dog.daycare_id = 5 and (dog.name ilike '%brown%' or dog.color ilike '%brown%');

How would I do that in Ecto?

1 Like

Take a look at Ecto.Query — Ecto v3.10.2


This worked perfectly, thank you!