NoBrainerORM / nobrainer

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

Nested hashes behave a bit oddly #39

Closed jakcharlton closed 10 years ago

jakcharlton commented 10 years ago

It seems assigning a value to a field (when it contains a hash) can leave the in memory record and the on disk one out of synch ...

machine = Machine.first
=> #<Machine id: "52b77aa32952f324c0000004", created_at: 2013-12-23 10:49:55 +1100, updated_at: 2013-12-23 13:26:37 +1100, name: "Machine1",  machine_memberships: {"role"=>"owner"}>

machine.machine_memberships = {newthing: 'y'}
machine.save!
Machine.first
=> #<Machine id: "52b77aa32952f324c0000004", created_at: 2013-12-23 10:49:55 +1100, updated_at: 2013-12-23 13:29:56 +1100, name: "Machine1", machine_memberships: {"newthing"=>"y", "role"=>"owner"}>
machine
#<Machine id: "52b77aa32952f324c0000004", created_at: 2013-12-23 10:49:55 +1100, updated_at: 2013-12-23 13:29:56 +1100, name: "Machine1", machine_memberships: {"newthing"=>"y"}>
nviennot commented 10 years ago

Oh crap, RethinkDB merges the hashes instead of replacing them :( This makes me sad. Perhaps it's time to start thinking about embedded documents.

nviennot commented 10 years ago

Fixed for now: https://github.com/nviennot/nobrainer/commit/836eae9d53c375c8ddf34a2b9990e771b5f283f9

jakcharlton commented 10 years ago

I knew about the merge instead of replace part - don't know if there's a way to say 'replace'

As to embedded docs, yeah they would be useful, but so would just plain Hashes be ... I'm still torn as to how much I'll use Nobrainer vs ReQL directly, as most of my app prefers hashes to models

On Mon, Dec 23, 2013 at 1:59 PM, Nicolas Viennot notifications@github.comwrote:

Oh crap, RethinkDB merges the hashes instead of replacing them :( This makes me sad. Perhaps it's time to start thinking about embedded documents.

— Reply to this email directly or view it on GitHubhttps://github.com/nviennot/nobrainer/issues/39#issuecomment-31102428 .

nviennot commented 10 years ago

Even though the issue is fixed, If your app prefers hashes to models, then nobrainer is probably not a good fit. (but I find it quite weird that your app prefers hashes over models).

If you need to use plain RQL more than 10% of the time, it means NoBrainer is useless and fails to deliver. I'd be happy to get your feedback to improve nobrainer.

PS: don't put symbols in your hashes, because they'll come back as strings.

jakcharlton commented 10 years ago

My app is using Rethink as it is heavily schema customisable by users.

Sometimes it helps to have a model, but in others it hurts. Dynamic attributes in Nobraimer will help somewhat, but I'm sure already there are things I'll need to use ReQL for

That's not to say Nobraimer is useless, it just solves one problem, not all of them :)

On 23 Dec 2013, at 2:08 pm, Nicolas Viennot notifications@github.com wrote:

Even though the issue is fixed, If your app prefers hashes to models, then nobrainer is probably not a good fit. (but I find it quite weird that your app prefers hashes over models).

If you need to use plain RQL more than 10% of the time, it means NoBrainer is useless and fails to deliver. I'd be happy to get your feedback to improve nobrainer.

PS: don't put symbols in your hashes, because they'll come back as strings.

— Reply to this email directly or view it on GitHub.

nviennot commented 10 years ago

Okay, well, let me know how I can assist your needs :)

jakcharlton commented 10 years ago

You've already been amazingly helpful and Nobrainer already solved the Devise issue :) just works

On 23 Dec 2013, at 2:20 pm, Nicolas Viennot notifications@github.com wrote:

Okay, well, let me know how I can assist your needs :)

— Reply to this email directly or view it on GitHub.

nviennot commented 10 years ago

Awesome!!

btw, I'd be happy to pair with you on your project :)

jakcharlton commented 10 years ago

Really appreciate the help and updates ... jakcharlton@gmail.com might save having conversations over issues threads :)