ActiveRecord::PreparedStatementInvalid wrong number of bind variables
When using any_of
on an association where the base object has no id set, results in errors.
class User
has_many :orders
end
```
```
irb(main):015:0> User.new.orders.where.any_of({source: "online"})
Traceback (most recent call last):
1: from (irb):10
ActiveRecord::PreparedStatementInvalid (wrong number of bind variables (2 for 1) in: `orders`.`user_id` IS NULL AND (1=0) AND `orders`.`source` = ?)
```
When the user object is persisted, it just works.
```
irb(main):018:0> User.first.orders.where.any_of({source: "online"})
User Load (30.5ms) SELECT `users`.* FROM `users` ORDER BY `users`.`id` ASC LIMIT 1 /*line:(irb):18:in `irb_binding'*/
Order Load (3.0ms) SELECT `orders`.* FROM `orders` WHERE `orders`.`user_id` = -1 AND (`orders`.`user_id` = -1 AND `orders`.`source` = 'online') LIMIT 11 /*line:/Users/lion/.asdf/installs/ruby/2.7.8/lib/ruby/2.7.0/irb/inspector.rb:109:in `block in <module:IRB>'*/
=> #<ActiveRecord::AssociationRelation []>
```
The array-based syntax also works with `User.new`
```
irb(main):017:0> User.new.orders.where.any_of(["source = ?", "online"])
=> #<ActiveRecord::AssociationRelation []>
```