samedi 13 juin 2015

Rails - why cannot I search through this hash?

I am running this piece of code:

car = Car.find(params[:id])
@new_car = Car.new

@new_car.car_services = car.car_services

What I am trying to do - I load from database an existing record based on the params[:id]. Then I create a new car and I am trying to assign the services from the loaded car to the one I am just creating (this line: @new_car.car_services = car.car_services).

When I print out what is in the car.car_services and @new_car.car_services - the output is the same. Totally the same.

Now comes the problem - when I try to search through it, like

car.car_services.where('cleaning="1"').inspect # I get filtered records
@new_car.car_services.where('cleaning="1"').inspect # I get nothing, empty output

I am battling with this issue half a day, but still don't know why the second case doesn't return any records.

Any tips? Thank you.

Aucun commentaire:

Enregistrer un commentaire