Fetching data from the database takes a lot time process. Eventually when you need to combine multiple tables in order to fetch the data, reducing database calls becomes very meaningful.
Although in CakePhp's model, by default if the association between various models either it be hasOne or belongsTo, hasMany can be done using find statement, as CakePHP will automatically use left joins and so with the sql statements for performing the DB calls.
So below we will discuss about the joins and fetching data using it.
The keys that define the joins are as follows:
1- table: The table for the join. 2- alias: An alias to the table or the name of the model associated 3- type: The type of join: inner, left or right. 4- conditions: The conditions to perform the join.
When using find() method, you can pass in option using 'joins' key to force a join statement below as an example: