Checks for the existence of the record in the first parameter. If it can't be found, the record in the second parameter is created.
Description | Accepted Data Types | Required ? | |
---|---|---|---|
1 | Find Criteria | {} ,[{}] , string , int |
Yes |
2 | Records to Create | {} ,[{}] |
Yes |
3 | Callback | function |
No |
Description | Possible Data Types | |
---|---|---|
1 | Error | Error |
2 | Records Created | {} , [{}] |
User.findOrCreate({name:'Walter'}, {name:'Jessie'}).exec(function createFindCB(err, record){
console.log('What\'s cookin\' '+record.name+'?');
});
// What's cookin' Jessie?
// Don't forget to handle your errors and abide by the rules you defined in your model
Any string arguments passed must be the ID of the record. If you are trying to find an attribute that is an array, you must wrap it in an additional set of brackets otherwise Waterline will think you want to perform an inQuery.