diegogub / aranGO

Golang driver for ArangoDB
Apache License 2.0
125 stars 31 forks source link

unique check: pass in actual value, not string version #44

Open makii42 opened 7 years ago

makii42 commented 7 years ago

Hi,

I was trying to enforce uniqueness on a int32 field in a model struct using models/context, and it just did not work, without a proper error message. While looking at the mechanism enforcing uniqueness I discovered the example query that is executed in collection.go:Unique This function gets passed the String()ed version of the reflect.Value, rather than the underlying value of the field. That might work for strings, but apparently does not for int fields. I found two instances where this happens:

Instead of passing the result of Value.String() I propose to pass Value.Interface() to make this work for non-string fields as well.

diegogub commented 7 years ago

hi @makii42, thanks. Let me check it.

makii42 commented 7 years ago

Hi @diegogub ,

I looked into the test failure yesterday for a while, and it seems there is no arangodb running as part of the test. I prepped a wercker.yml locally that's working, and added some code to config_test.go that uses a db at localhost and flips over to one provided in a service container if it's running in wercker. I'll add it to the PR in a bit.

Unfortunately, one test still fails in simple.test.go when using Cursor.FetchOne(). This seems unrelated to my change though.

Best, -Ralf

makii42 commented 7 years ago

Okay, that's weird - I just set up a wercker build on my fork, and it gets as far as I get when I use the wercker client locally... wercker status