Using Matching and NotMatching in Cakephp
A) Matching()
Matching () will be provided like join level of mysql query. This query helps to find the match record from associated table.
For example if you have ‘Table1 belongsToMany Table2′ you will probably want to find table1 that have the ‘CakePHP’
value of name field in ‘table2’. This is very simple to do with the ORM in CakePHP :
// In a controller or table method.
$query = $table1->find();
$query->matching(‘Table2’, function ($q) {
return $q->where([‘Table2.name’ => ‘CakePHP’]);
});
Output: Table 1 get unique record on bases of table2 has name field value ‘cakePHP’.
B) NotMatching()
This method is opposite of the Matching().In this query result is not related to association table.
See example if you have ‘Table1 belongsToMany Table2′ you will probably want to find table1 that have the ‘CakePHP’ value of name
field in ‘table2’. This is very simple to do with the ORM in CakePHP
// In a controller or table method.
$query = $table1->find();
$query->notMatching(‘Table2’, function ($q) {
return $q->where([‘Table2.name’ => ‘CakePHP’]);
});
Output: Table 1 get record that record not in table2 has name field value ‘cakePHP’.
Read Also:-
Routing in Laravel(Laravel Routes)
Basic Shape Tools in Photoshop
Also Visit:-