model.find => model.findById, model.all => model.find
This commit is contained in:
parent
66281d7c23
commit
88f634df38
12
README.md
12
README.md
|
@ -180,7 +180,7 @@ Query count of Model instances in data source. Optional query param allows to co
|
|||
console.log(count); // 2081
|
||||
});
|
||||
|
||||
##### Model.all(filter, callback)
|
||||
##### Model.find(filter, callback)
|
||||
|
||||
Find all instances of Model, matched by query. Fields used for filter and sort should be declared with `{index: true}` in model definition.
|
||||
|
||||
|
@ -194,7 +194,7 @@ Find all instances of Model, matched by query. Fields used for filter and sort s
|
|||
|
||||
Find the second page of 10 users over age 21 in descending order.
|
||||
|
||||
User.all({where: {age: {gt: 21}}, order: 'age DESC', limit: 10, skip: 10})
|
||||
User.find({where: {age: {gt: 21}}, order: 'age DESC', limit: 10, skip: 10})
|
||||
|
||||
**Note:** See the specific connector's [docs](#connectors) for more info.
|
||||
|
||||
|
@ -202,11 +202,11 @@ Find the second page of 10 users over age 21 in descending order.
|
|||
|
||||
Delete all Model instances from data source. **Note:** destroyAll method does not perform destroy hooks.
|
||||
|
||||
##### Model.find(id, callback)
|
||||
##### Model.findById(id, callback)
|
||||
|
||||
Find instance by id.
|
||||
|
||||
User.find(23, function(err, user) {
|
||||
User.findById(23, function(err, user) {
|
||||
console.info(user.id); // 23
|
||||
});
|
||||
|
||||
|
@ -382,7 +382,7 @@ Remote hooks also support wildcards. Run a function before any remote method is
|
|||
|
||||
Other wildcard examples
|
||||
|
||||
// run before any static method eg. User.all
|
||||
// run before any static method eg. User.find
|
||||
User.beforeRemote('*', ...);
|
||||
|
||||
// run before any instance method eg. User.prototype.save
|
||||
|
@ -703,7 +703,7 @@ Find the 3 nearest coffee shops.
|
|||
|
||||
CoffeeShop.attach(oracle);
|
||||
var here = new GeoPoint({lat: 10.32424, long: 5.84978});
|
||||
CoffeeShop.all({where: {location: {near: here}}}, function(err, nearbyShops) {
|
||||
CoffeeShop.find({where: {location: {near: here}}}, function(err, nearbyShops) {
|
||||
console.info(nearbyShops); // [CoffeeShop, ...]
|
||||
});
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
"debug": "latest",
|
||||
"express": "~3.1.1",
|
||||
"jugglingdb": "git+ssh://git@github.com:strongloop/jugglingdb.git",
|
||||
"merge": "~1.1.0",
|
||||
"sl-remoting": "git+ssh://git@github.com:strongloop/sl-remoting.git",
|
||||
"inflection": "~1.2.5"
|
||||
},
|
||||
|
|
|
@ -10,14 +10,14 @@ describe('DataSource', function() {
|
|||
describe('dataSource.createModel(name, properties, settings)', function() {
|
||||
it("Define a model and attach it to a `DataSource`.", function() {
|
||||
var Color = memory.createModel('color', {name: String});
|
||||
assert.isFunc(Color, 'all');
|
||||
assert.isFunc(Color, 'find');
|
||||
assert.isFunc(Color, 'findById');
|
||||
assert.isFunc(Color, 'findOne');
|
||||
assert.isFunc(Color, 'create');
|
||||
assert.isFunc(Color, 'updateOrCreate');
|
||||
assert.isFunc(Color, 'upsert');
|
||||
assert.isFunc(Color, 'findOrCreate');
|
||||
assert.isFunc(Color, 'exists');
|
||||
assert.isFunc(Color, 'find');
|
||||
assert.isFunc(Color, 'findOne');
|
||||
assert.isFunc(Color, 'destroyAll');
|
||||
assert.isFunc(Color, 'count');
|
||||
assert.isFunc(Color, 'include');
|
||||
|
@ -47,7 +47,6 @@ describe('DataSource', function() {
|
|||
existsAndShared('findOrCreate', false);
|
||||
existsAndShared('exists', true);
|
||||
existsAndShared('find', true);
|
||||
existsAndShared('all', true);
|
||||
existsAndShared('findOne', true);
|
||||
existsAndShared('destroyAll', false);
|
||||
existsAndShared('count', true);
|
||||
|
|
|
@ -13,7 +13,7 @@ describe('Model', function() {
|
|||
'domain': String,
|
||||
'email': String
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
describe('Model.validatesPresenceOf(properties...)', function() {
|
||||
it("Require a model to include a property to be considered valid.", function() {
|
||||
|
@ -111,11 +111,11 @@ describe('Model', function() {
|
|||
it("Attach a model to a [DataSource](#data-source)", function() {
|
||||
var MyModel = asteroid.createModel('my-model', {name: String});
|
||||
|
||||
assert(MyModel.all === undefined, 'should not have data access methods');
|
||||
assert(MyModel.find === undefined, 'should not have data access methods');
|
||||
|
||||
MyModel.attachTo(memory);
|
||||
|
||||
assert(typeof MyModel.all === 'function', 'should have data access methods after attaching to a data source');
|
||||
assert(typeof MyModel.find === 'function', 'should have data access methods after attaching to a data source');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -178,10 +178,10 @@ describe('Model', function() {
|
|||
describe('model.destroy([callback])', function() {
|
||||
it("Remove a model from the attached data source.", function(done) {
|
||||
User.create({first: 'joe', last: 'bob'}, function (err, user) {
|
||||
User.find(user.id, function (err, foundUser) {
|
||||
User.findById(user.id, function (err, foundUser) {
|
||||
assert.equal(user.id, foundUser.id);
|
||||
foundUser.destroy(function () {
|
||||
User.find(user.id, function (err, notFound) {
|
||||
User.findById(user.id, function (err, notFound) {
|
||||
assert(!err);
|
||||
assert.equal(notFound, null);
|
||||
done();
|
||||
|
@ -214,10 +214,10 @@ describe('Model', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Model.find(id, callback)', function() {
|
||||
it("Find instance by id.", function(done) {
|
||||
describe('Model.findById(id, callback)', function() {
|
||||
it("Find an instance by id.", function(done) {
|
||||
User.create({first: 'michael', last: 'jordan', id: 23}, function () {
|
||||
User.find(23, function (err, user) {
|
||||
User.findById(23, function (err, user) {
|
||||
assert.equal(user.id, 23);
|
||||
assert.equal(user.first, 'michael');
|
||||
assert.equal(user.last, 'jordan');
|
||||
|
|
Loading…
Reference in New Issue