@@ -474,7 +474,7 @@ Task.drop() // will emit success or failure event
...
@@ -474,7 +474,7 @@ Task.drop() // will emit success or failure event
Project.[sync|drop]().then(function(){
Project.[sync|drop]().then(function(){
// ok ... everything is nice!
// ok ... everything is nice!
}).catch(function(error){
}).catch(function(error){
// oooh, did you entered wrong database credentials?
// oooh, did you enter wrong database credentials?
})
})
```
```
...
@@ -584,7 +584,7 @@ Project.find({
...
@@ -584,7 +584,7 @@ Project.find({
### findOrCreate - Search for a specific element or create it if not available
### findOrCreate - Search for a specific element or create it if not available
The method `findOrCreate` can be used to check if a certain element is already existing in the database. If that is the case the method will result in a respective instance. If the element does not yet exist, it will be created.
The method `findOrCreate` can be used to check if a certain element already exists in the database. If that is the case the method will result in a respective instance. If the element does not yet exist, it will be created.
Let's assume we have an empty database with a `User` model which has a `username` and a `job`.
Let's assume we have an empty database with a `User` model which has a `username` and a `job`.
...
@@ -637,7 +637,7 @@ User
...
@@ -637,7 +637,7 @@ User
### findAndCountAll - Search for multiple elements in the database, returns both data and total count
### findAndCountAll - Search for multiple elements in the database, returns both data and total count
This is a convienience method that combines`findAll()`and`count()`(see below), this is useful when dealing with queries related to pagination where you want to retrieve data with a`limit`and`offset`but also need to know the total number of records that match the query.
This is a convienience method that combines`findAll`()and `count`()(see below), this is useful when dealing with queries related to pagination where you want to retrieve data with a `limit` and `offset`but also need to know the total number of records that match the query.
The success handler will always receive an object with two properties:
The success handler will always receive an object with two properties:
...
@@ -660,7 +660,7 @@ Project
...
@@ -660,7 +660,7 @@ Project
});
});
```
```
The options [object] that you pass to`findAndCountAll()`is the same as for`findAll()`(described below).
The options [object] that you pass to`findAndCountAll`()is the same as for`findAll`()(described below).
### findAll - Search for multiple elements in the database
### findAll - Search for multiple elements in the database
When you are retrieving data from the database there is a fair chance that you also want to get their associations. This is possible since`v1.6.0`and is called eager loading. The basic idea behind that, is the use of the attribute`include`when you are calling`find`or`findAll`. Lets assume the following setup:
When you are retrieving data from the database there is a fair chance that you also want to get their associations. This is possible since`v1.6.0`and is called eager loading. The basic idea behind that, is the use of the attribute`include` when you are calling `find` or `findAll`. Lets assume the following setup:
Notice that the accessor is plural. This is because the association is many-to-something.
Notice that the accessor is plural. This is because the association is many-to-something.
If an association is aliased (using the`as`option), you_must_specify this alias when including the model. Notice how the user's`Tool`s are aliased as`Instruments`above. In order to get that right you have to specify the model you want to load, as well as the alias:
If an association is aliased (using the`as`option), you must specify this alias when including the model. Notice how the user's `Tool`s are aliased as `Instruments`above. In order to get that right you have to specify the model you want to load, as well as the alias: