Recursive in CakePHP - Explanation

2

I'd like to know, by way of example, how CakePHP recursive works.

$this->Model->recursive=2;

What exactly does it do in practice?

    
asked by anonymous 08.06.2015 / 16:49

1 answer

2

According to documentation , the recursive property defines how much background CakePHP should go to fetch the records associated with a data model using the methods find and / or read .

  

Imagine that your application is Groups that belong to a    domain that has multiple Users which in turn has several Articles .

     

You can set the recursive property to different values with   on the amount of data you want to return from a call, for   example $this->Group->find() :

     
  • -1 Search data only from Group , without join.
  •   
  • 0 Search for Group and domain   
  • Search for a Group , its domain and its associated Users .   
  • Search for a Group , its domain , its associated Users and articles > associated with Users .
  •   

The default is 1 . The recommended recursion level is 2 . That   avoids returning related data that is unnecessary or even   undesirable

See also Retrieving Your Data in of blog     

08.06.2015 / 18:30