src code

class method ActiveRecord.Model.find

ActiveRecord.Model.find(id) → Boolean | Object
ActiveRecord.Model.find(array_of_ids) → Array
ActiveRecord.Model.find(params) → Array
ActiveRecord.Model.find(sql_statement) → Array

Find a given record, or multiple records matching the passed conditions. Params may contain:

  • select (Array) of columns to select, default ['*']
  • where (String | Object | Array)
  • joins (String)
  • order (String)
  • limit (Number)
  • offset (Number)
  • callback (Function)
//finding single records
var user = User.find(5);
var user = User.find({
    first: true,
    where: {
        id: 5
    }
});
var user = User.find({
    first: true,
    where: ['id = ?',5]
});
 //finding multiple records
var users = User.find(); //finds all
var users = User.find(1,2,3); //finds ids 1,2,3
var users = User.find([1,2,3]); // finds ids 1,2,3
 //finding multiple records with complex where statements
var users = User.find({
    where: 'name = "alice" AND password = "' + md5('pass') + '"',
    order: 'id DESC'
});
 var users = User.find({
    where: ['name = ? AND password = ?','alice',md5('pass')],
    order: 'id DESC'
});
 //using the where syntax below, the parameters will be properly escaped
var users = User.find({
    where: {
        name: 'alice',
        password: md5('pass')
    }
    order: 'id DESC'
});
 //find using a complete SQL statement
var users = User.find('SELECT * FROM users ORDER id DESC');
 //find using a callback, "user" in this case only contains a hash
//of the user attributes, it is not an ActiveRecord instance
var users = User.find({
    callback: function(user){
         return user.name.toLowerCase() == 'a';
    }
});