How to perform a has_many interaction query in Ruby on Rails

Asked

Viewed 41 times

0

I’m having difficulty searching with has_many interactions in ruby on Rails. Goal is to search all vehicles that have no fines type 'guy'... The problem is that the query I made still returns several vehicles with the type 'guy'. I’m trying to perform the search like this:

veiculos = Veiculo.joins(:multas).where.not(multas: { tipo: 'cara' }).group('veiculos.id')

Where am I going wrong?

1 answer

0

veiculos = Veiculo.joins(:multas).where.not('multas.tipo = ?', "cara")
  • Can you explain what the code does? It’s the solution to the question posed?

  • The variable vehicles is an Active Record that picks up all models Vehicle that has the model Fine with the column "type" with the face value. The code picks up the table Vehicles, makes a Join table with the table Fines and of those takes all the fines that the column type are "expensive"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.