I was using RethinkDB in my recent project and found that first_or_create is not working as it should be. Here is the script to reproduce the issue.
# in first_or_create.rb
require 'rubygems'
require 'nobrainer'
NoBrainer.configure do |config|
config.rethinkdb_url = "rethinkdb://localhost/dummy_test"
end
class User
include NoBrainer::Document
field :name, :uniq => true
field :email
end
params = { name: 'Test', email: 'kd.engineer@yahoo.co.in' }
User.where(name: params[:name]).first_or_create(params) # this should not raise error.
$ ruby first_or_create.rb
/Users/kuldeepaggarwal/.rvm/gems/ruby-2.2.2/gems/nobrainer-0.27.0/lib/no_brainer/criteria/first_or_create.rb:58:in `_first_or_create': where() and first_or_create() were given conflicting values on the following keys: [:name] (RuntimeError)
from /Users/kuldeepaggarwal/.rvm/gems/ruby-2.2.2/gems/nobrainer-0.27.0/lib/no_brainer/criteria/first_or_create.rb:5:in `first_or_create'
from first_or_create.rb:17:in `<main>'
If it is really an issue then I would like to raise a PR to fix this issue.
I was using
RethinkDB
in my recent project and found thatfirst_or_create
is not working as it should be. Here is the script to reproduce the issue.If it is really an issue then I would like to raise a PR to fix this issue.