0

I'm trying to store a hierarchical structure using the Nested Set Model technique. I'm using Waterline ORM for node to query and update my database. How would I model the following query using Waterline?

UPDATE MyTable SET counter=counter+2 WHERE id > 4 AND id < 17;

I'm aware of MyTable.update(...) but I'm not sure how to reference an existing column value in the query.

alarner
  • 175
  • 1
  • 7

1 Answers1

0

There's currently no way to reference existing field values in a Waterline update query, although it's a feature that's certainly been discussed.

In the meantime, if you don't want to follow a two-step process (MyTable.find followed by a loop and .save() for each instance), then you'll need to use native DB methods to accomplish this. For sails-mysql and sails-postgresql adapters, that means using .query():

MyTable.query("UPDATE MyTable SET counter=counter+2 WHERE id > 4 AND id < 17", 
              function(err, results) {...});

For the sails-mongo adapter, the analogous method is .native().

sgress454
  • 24,870
  • 4
  • 74
  • 92