-
Notifications
You must be signed in to change notification settings - Fork 23
How to use Coloquent
DavidDuwaer edited this page Aug 31, 2017
·
17 revisions
The usage example below, of which the class definitions of Teacher, Student, School and Address are not shown, shows how Coloquent is used to
- Build an HTTP request to retrieve an assembly of models
- Retrieve full-fledged interrelated models from Coloquent's response
Teacher
.where('gender', 'm') // sets a filter
.with('students') // eager loads related models
.with('schools.address') // eager loads directly and indirectly related models
.get() // submits the HTTP request, returns an ES6 Promise
.then(function (response: PluralResponse) {
let teachers = response.getData();
foreach (let teacher of teachers) {
let students = teacher.getStudents();
let schools = teacher.getSchools();
foreach (let school of schools) {
let address = school.getAddress();
}
}
});