-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
as_array for multiple results #17
Comments
Idea: Make as_array() work on unexecuted queries. So, you could call |
I solve the problem this (into idiorm.php): public static function to_array( $arr_orm ) { $salida = array(); if( is_array( $arr_orm ) ) { $size = sizeof( $arr_orm ); for( $i = 0; $i < $size; ++$i ) { $obj = $arr_orm[$i]; if ( $obj instanceof ORM ) { $salida[$i] = $arr_orm[$i]->as_array(); } } } return $salida; } And you can use this way:
$tnomina = ORM::for_table('nomina.tnomina')->find_many();
ORM::to_array( $tnomina )
|
Hello, here's my correction for the above solution : public static function to_array($result) {
$array = array();
foreach ($result as $r) {
$array[] = (array) $r->_data;
}
return $array;
} |
You don't need that code, use this one instead... less resources consuming since _run it's returning the array you are looking for:
$tnomina = ORM::for_table('nomina.tnomina')->find_array(); |
@Surt Where should this code go? If I try accessing the properties of my orm objects in my application, I just get null values, presumably because the properties are protected? |
It goes directly before, or after find_many or find_one, as another method. $tnomina = ORM::for_table('nomina.tnomina')->find_array(); array( |
@Surt - thanks. Works great. Perhaps there should be a PR for this? |
@Surt, man it's great) thanks a lot. |
From Osman Üngür (by email):
The text was updated successfully, but these errors were encountered: