Jasper Tey Wed Jan 19 19:07:39 -0500 2011

Subject: Retrieve an entire result-set in json form?

Is it possible to retrieve an entire result-set in json form? For example:

$users = User::all(); // returns an array of User objects

I know you can apply to_json() for each Model object individually, but I am looking to retrieve all the rows in json format, without having to iterate over each row and apply the to_json function individually. An example of where I need to do this is when using jQuery UI's Autocomplete--currently I am going the custom SQL query route using PHP's native db functions to return an array of associative arrays (rows), and then use PHP's json_encode function. I would rather use the phpactiverecord library to achieve the same thing... ideas?

Kien La Fri Jan 21 22:49:52 -0500 2011

No, this isn't currently supported because right now we are returning raw arrays. We do have a patch from someone to return ArrayObjects instead which would allow this to work but we're debating whether the performance trade off of using ArrayObjects will be worth it.