This is a personalized reference for functions I have used. Any excluded parameters or simplifications are intentional.
##Function Summary
function | param1 | param2 | response |
---|---|---|---|
.find |
PK or {} |
NA | [{}] |
.findOrCreate |
PK or {} |
{} |
{} |
.destroy |
PK or {} |
NA | [{}] |
.update |
PK or {} |
{} |
[{}] |
PK = primary key; int or string. | |||
{} = Single record. |
|||
[{}] = An array of records. |
##Errors
###Uncaught SyntaxError: Unexpected end of input
Problem: Callbacks continue to execute after a res.send()
. I keep assuming the block will end like at a return;
, but the callback continues and encountering another send()
will cause this type of error.
Fix: Either add return;
after every send()
call or use multiple if-else-if bracketing to prevent executing code after a res.send()
.
###criteria not found
Problem: Getting a criteria not found
error when using a string
or int
to find a record. Probably occurs if a string
id is not getting properly cast as an int
or vice versa when searching the database.
Fix: Use bracketed (JSON) notation for the criteria. Model.find({id: pkvalue}, cb)
and not Model.find(pkvalue, cb)
.
##Warning
###Using create
with an array or new records will not return an array in the same order.
##Find Model.find(criteria, function (err, record) {}); Model.find(criteria).exec(function (err, record) {});
criteria
= primary key value or json matchingfunction
= Callbackreclist
= Array of record objects- NOTE: Always returns an array.
##Find or Create Model.findOrCreate(criteria, object, function (err, record) {}); Model.findOrCreate(criteria, object).exec(function (err, record) {});
criteria
= primary key value or json matching- NOTE:
criteria not found
error may require brackets around named id or criteria{id: value}
.
- NOTE:
object
= record to create.- NOTE: Can contain additional parameters which are ignored.
function
= Callbackrecord
= record object- NOTE: I can only get this to work on single records so far.
##Destroy Model.destroy(criteria, function (err, recList) {}); Model.destroy(criteria).exec(function (err, recList) {});
criteria
= Find Criteria{},[{}], string, int
function
= CallbackrecList
= Always returns anArray
##Update Model.update(criteria, object, function (err, recList) {}); Model.update(criteria, object).exec(function (err, recList) {});
criteria
= Find Criteria{},[{}], string, int
object
= record to create.- NOTE: Can contain additional parameters which are ignored.
function
= CallbackrecList
= Always returns anArray