This method convert all mapped informationg (including cascating relatioinships) into a JSON format to better manage it into views or anything you want to.
By default recursive is true and full recursive is false.
Recursive means it will take all relationships ( currently or not ) and convert in a zero level to array too.
@param Boolean $recursive
@return JSON String
Params
$recursive
By default toJSON() method brings the Model recursively that menas it will bring all current relationships instanced at that time recusively. If $recursive = false than it will bring only the first level.
Explanation
Default Usage
$user = new Users(); $user->get(1); print_r($user->toJSON());
It will print something like: “{ ‘id_user’ : 1, ‘first_name’ : ‘Klederson’, ‘last_name’ : ‘Bueno’, ‘birthday’ : ’1986-05-17′, ‘gender’ : ‘male’, ‘created_at’ : ’2010-06-27′}”
Relationships default
*Assuming we have a albums relationship mapped
$user = new Users();
$user->get(1)
->getRelationship('albums',true)
->fetch();
print_r($user->toJSON());
It will print something like: “{ ‘id_user’ : 1, ‘first_name’ : ‘Klederson’, ‘last_name’ : ‘Bueno’, ‘birthday’ : ’1986-05-17′, ‘gender’ : ‘male’, ‘created_at’ : ’2010-06-27′, ‘albums’ : [{ 'id_album' : 1, 'name' : 'My Travel', 'created_at' : '2010-06-27' }]}”
Relationships $recursive = false
*Assuming we have a albums relationship mapped
$user = new Users();
$user->get(1)
->getRelationship('albums',true)
->fetch();
print_r($user->toJSON(false));
It will print something like: “{ ‘id_user’ : 1, ‘first_name’ : ‘Klederson’, ‘last_name’ : ‘Bueno’, ‘birthday’ : ’1986-05-17′, ‘gender’ : ‘male’, ‘created_at’ : ’2010-06-27′}“
