upsert does not work with associations #186

Closed
niv opened this Issue Feb 1, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@niv

niv commented Feb 1, 2016

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 nviennot closed this in ae5b98b Feb 1, 2016

@nviennot

This comment has been minimized.

Show comment
Hide comment
@nviennot

nviennot Feb 1, 2016

Owner

I've fixed this bug.

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

Owner

nviennot commented Feb 1, 2016

I've fixed this bug.

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

@niv

This comment has been minimized.

Show comment
Hide comment
@niv

niv Feb 1, 2016

Tyvm! That was amazingly quick.

niv commented Feb 1, 2016

Tyvm! That was amazingly quick.

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