update query logic , so it is compatible with Grape