toArray()

toArray($recursive = true, $full = false, $insane = false)

This method convert all mapped informationg (including cascating relatioinships) into a array 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 Array

Params


$recursive
By default toArray() 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->toArray());

It will print something like: “Array( ‘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->toArray());

It will print something like: “Array( ‘id_user’ => 1, ‘first_name’ => ‘Klederson’, ‘last_name’ => ‘Bueno’, ‘birthday’ => ‘1986-05-17’, ‘gender’ => ‘male’, ‘created_at’ => ‘2010-06-27’, ‘albums’ => Array( ‘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->toArray(false));

It will print something like: “Array( ‘id_user’ => 1, ‘first_name’ => ‘Klederson’, ‘last_name’ => ‘Bueno’, ‘birthday’ => ‘1986-05-17’, ‘gender’ => ‘male’, ‘created_at’ => ‘2010-06-27’))