Unwanted Behaviour of `Model.first_or_create` #151

Closed
kuldeepaggarwal opened this Issue Jul 20, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@kuldeepaggarwal

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.

@nviennot nviennot closed this in d3b3410 Jul 20, 2015

@nviennot

This comment has been minimized.

Show comment
Hide comment
@nviennot

nviennot Jul 20, 2015

Owner

Thanks for the detailed bug report 👍 👍 😄

Owner

nviennot commented Jul 20, 2015

Thanks for the detailed bug report 👍 👍 😄

@kuldeepaggarwal

This comment has been minimized.

Show comment
Hide comment
@kuldeepaggarwal

kuldeepaggarwal Jul 20, 2015

Now I can use first_or_create in my project. 😄 Thanks for quick fix.

Now I can use first_or_create in my project. 😄 Thanks for quick fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment