kohana / database

A Kohana module for database interactions, building queries, and prepared statements
http://kohanaframework.org/documentation
158 stars 140 forks source link

Added method each_as_array(). Is like a recursive as_array() for databas... #25

Closed alejandroiglesias closed 12 years ago

alejandroiglesias commented 12 years ago

...e results.

Kohana-Builds commented 12 years ago

Pull request is targeted towards an invalid branch (3.2/master). Usually, this means you have targeted the master, rather than develop branch. Please correct this and try again. Thanks!

alejandroiglesias commented 12 years ago

Pull request targeted at branch 3.2/master and should be 3.2/develop.

shadowhand commented 12 years ago

This is invalid anyways, if you don't want the results as objects, use: $query->as_object(FALSE)->execute()->as_array().

alejandroiglesias commented 12 years ago

Oh, great info! Thank you very much Woody!

2011/12/2 Woody Gilk < reply@reply.github.com

This is invalid anyways, if you don't want the results as objects, use: $query->as_object(FALSE)->execute()->as_array().


Reply to this email directly or view it on GitHub: https://github.com/kohana/database/pull/25#issuecomment-2997459

alejandroiglesias commented 12 years ago

Ohh, but you can't use that with models, just with Database_Builder. My proposal is for Database_Result, so we can do: $users_array = ORM::factory('user')->find_all()->each_as_array();

ernestas commented 12 years ago

@alejandrogarciaiglesias

http://forum.kohanaframework.org/discussion/9488/oop-design-question-where-should-as_array_recursive-go http://dev.kohanaframework.org/issues/4193

alejandroiglesias commented 12 years ago

Thank you very much!

2011/12/6 Ernestas Lisauskas < reply@reply.github.com

@alejandrogarciaiglesias

http://forum.kohanaframework.org/discussion/9488/oop-design-question-where-should-as_array_recursive-go http://dev.kohanaframework.org/issues/4193


Reply to this email directly or view it on GitHub: https://github.com/kohana/database/pull/25#issuecomment-3032310

alejandroiglesias commented 12 years ago

So why there is a as_array() method if Database_Result shouldn't take care of data format?

deeceefar2 commented 12 years ago

This is what I use to accomplish this:

$data_as_array = array_map( create_function( '$obj', 'return method_exists($obj,"as_array") ? $obj->as_array() : $obj;'), ORM::factory('user')->find_all()->as_array());

This should accomplish what you want though it isn't pretty.

alejandroiglesias commented 12 years ago

Not pretty!