Skip to content
Advertisement

How to select records with zero associations from two nested has_many?

Some days ago I asked the following question: How to select records with zero associations from two has many?

I failed to adapt the answer that solved my previous question to this similar situation:

These are the corresponding migrations:

Here is a more visual description:

enter image description here

How to select journeys whose stops don’t have any associated report as departure or arrival ?

What I’m looking for would be equivalent to this:

Edit

Trying the solution proposed by Sebastian Palma:

I get the following sql query:

With this error:

Advertisement

Answer

Have following model side changes,

And get journeys having both

Good part of above is, only single query is fired even inner attributes are passed by calling another query.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement