Giter Site home page Giter Site logo

Comments (10)

mde avatar mde commented on August 30, 2024

You can use the static update method on the constructor -- pass it a params object (or an instance with all the properties set the way you want), and a query object which will return all the instances you want to update:

https://github.com/geddy/model/blob/master/lib/index.js#L504

from model.

danfinlay avatar danfinlay commented on August 30, 2024

Whoah! That's fantastic! I can't believe I hadn't seen this.

from model.

mde avatar mde commented on August 30, 2024

Is this not documented? I thought it was.

from model.

mde avatar mde commented on August 30, 2024

Delete does the same thing.

from model.

danfinlay avatar danfinlay commented on August 30, 2024

I haven't seen it in any docs, and I did a brief additional scan.

from model.

mde avatar mde commented on August 30, 2024

I remember a bunch of back-and-forth about this before with delete, probably because it's not documented.

from model.

danfinlay avatar danfinlay commented on August 30, 2024

This'll be easy to document. I say leave this open or another issue to document those, it's a nice easy one for anyone to contribute.

I'd do it now but I'm craaaazy swamped.

from model.

OscarGodson avatar OscarGodson commented on August 30, 2024

Took some digging but I finally got it to work. I feel like I'm doing it wrong tho. To get this to work I noticed in the code the type of model needs to be passed in with the data despite already being an instance of model with a type, like this:

NotificationModel.update({read: true, type: 'Notification'}, { userId: id, read: false  }, function (err, notificationModels) {

If you don't pass this you get an error (because of this line: https://github.com/geddy/model/blob/master/lib/adapters/sql/base.js#L132).

from model.

mde avatar mde commented on August 30, 2024

Weird, and seemingly a bug. It should already know what its type is.

from model.

mde avatar mde commented on August 30, 2024

Ah, that assumes you're using an actual instance for the data object, which was the original use -- you can also arrive at the update method via the save instance method on an previously created-and-saved item. This should be pretty easily fixable.

from model.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.