T
T
The Whiz2014-11-11 15:34:53
PostgreSQL
The Whiz, 2014-11-11 15:34:53

How to change active record to fulfill double condition with joins?

I have such a query in ActiveRecord on my project, which returns categories based on the presence of providers in subcategories:

Category.joins(subcategories: [:service_providers]).uniq

Can you tell me how to substitute a double condition so that only those categories are returned, in the subcategories of which there is at least one service_provider with the status published: true?
Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vsuhachev, 2014-11-11
@modernstyle

Category.joins(
  subcategories: :service_providers
).where(service_providers: { published: true }).uniq

It is assumed that your table is called service_providers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question