1602 / jugglingdb

Multi-database ORM for nodejs: redis, mongodb, mysql, sqlite3, postgresql, arango, in-memory...
http://1602.github.io/jugglingdb/
2.05k stars 241 forks source link

Is it possible to remove property from a model? #412

Closed coodoo closed 8 years ago

coodoo commented 10 years ago

Say in a User model, I accidentally put in user.foo = "bar" and saved, is there a way to remove 'foo' from the database and model itself?

alexbaumgertner commented 10 years ago

See model docs and source code. Unfortunately, I can not find explicit ways to delete an attribute of the model, try updateAttribute with null, empty or undefined value.

coodoo commented 10 years ago

Tried following steps, no luck.

  1. user.foo = null; then save result: user.foo become null, but still exists
  2. delete user.foo; then save result: no op, value doesn't change
  3. user.updpateAttribute('foo', null, cb) result: no op, value doesn't change, I also tried undefined to the same effect.
alexbaumgertner commented 10 years ago

Which database engine do you use (MySQL, Mongo, etc...) ?

coodoo commented 10 years ago

Mongodb, currently the only way I know is by using $unset directly.

alexbaumgertner commented 10 years ago

Mmm... it seems that you need to add this functionality to jugglingdb/mongodb-adapter

alexbaumgertner commented 10 years ago

For example, to MongoDB.prototype.updateAttributes.

coodoo commented 10 years ago

ah, thanks for the pointer, so this one has to be implemented in every adapter, instead of being generalized into a higher level function?

alexbaumgertner commented 10 years ago

We need to ask @anatoliychakkaev @1602 about adapters. The question is "What we can to remove property from a model". Lets wait for an answer :)

anatoliychakkaev commented 10 years ago

It should be implemented in mongodb adapter. When value set to null it should call $unset.

On Tue, Jul 29, 2014 at 3:45 PM, Alex Baumgertner notifications@github.com wrote:

We need to ask @anatoliychakkaev @1602 about adapters. The question is "What we can to remove property from a model".

Lets wait for an answer :)

Reply to this email directly or view it on GitHub: https://github.com/1602/jugglingdb/issues/412#issuecomment-50465605

coodoo commented 10 years ago

Thanks for the reply, but what about other database like MySQL? Can this be a higher level function inside the ORM itself?

1602 commented 8 years ago

In mysql this is working fine, null in js becomes null in database. I will add test for that.