Neo4j.rb How to make one query when filtering parameter may or may not be present?

60 views Asked by At

User and Place are the two nodes having has_many realtionship

@places = User.find(4).places

@places = @places.where(dog: false) if params[:no_dogs]

can I make these two into one so that if param comes then it involve where condition other wise ignore it

1

There are 1 answers

1
Brian Underwood On

I don't believe that the find() method takes zero arguments. Maybe you're wanting this?

@places = User.places # Calling the association gives an unexecuted proxy to a query to build

@places = @places.where(dog: false) if params[:no_dogs]

Or if you wanted to work with the User model:

@users = User.all

@users = @users.where(dog: false) if params[:no_dogs]