NoBrainerORM / nobrainer

Ruby ORM for RethinkDB
http://nobrainer.io/
Other
387 stars 49 forks source link

upsert does not work with associations #186

Closed niv closed 8 years ago

niv commented 8 years ago

Just a small bug report: I can't get upsert! to work on associations, like so:

class Parent; ... end
class MyModel
  include BaseModel
  belongs_to :parent
  field :username, String
  field :data, String, unique: { scope: [:parent_id, :username] }
end

MyModel.upsert! parent: @parent, username: "me", data: "test"

It fails on not finding a matching uniqueness validator (because it's looking for :parent_id instead of :parent). As a consequence, if I do

MyModel.upsert! parent_id: @parent.id, username: "me", data: "test"

it works as expected.

(Note that I had to set the uniq validator on :data to look for :parent_id, too, instead of :shard.)

nviennot commented 8 years ago

I've fixed this bug.

I've also added the :uniq/unique option on a belongs_to declaration

niv commented 8 years ago

Tyvm! That was amazingly quick.