Kohana 3 ORM as_array returns an ORM array

I am doing a simple query and want to return an array. Based on the ORM tutorial that comes with the Kohana 3 tutorial, I thought I could do the following:

ORM::factory('user')->find_all()->as_array();

But this seems to give me an array of model objects (i.e. an array (User_Model1, User_Model2 ...

Looking at the source, I see that I can easily fix this by cracking the next patch.

modules/database/classes/kohana/database/result.php
@@ -94,7 +94,7 @@
                        foreach ($this as $row)
                        {
-                               $results[] = $row;
+                               $results[] = $row->as_array();

Which seems to be more consistent with what the user manual says:

A powerful feature of ORM is the ORM :: as_array method, which returns the specified record as an array. If used with ORM :: find_all, an array of all records will be returned. A good example of when this is useful is a list of choices:

// ( id ) echo    :: select ('user', ORM:: factory ('user') → find_all() → as_array ('id', 'username'));

, , , ? , ?

+3
3

, (?), , , , "" . , ORM ( ) .

:

  • as_array() , ( , ),
  • , ,

, :

  • ,
  • methon - ( Kohana , , /).

Kohana_Database_Result, Database_Result application/class/database/result.php Kohana_Database_Result, , ( ).

+4

ORM, , , (, , ). . :

$output = $this->_db->query(Database::SELECT, "select * from users");

Database::query() .

0

ORM has no methods described by you. In Kohana 2.3.4, is there a select_list () method that may contain incorrect information from the old (or future) version?

PS. And there is no reason to modify the DB Result object, because it $rowcan be any class (not just ORM).

-1
source

Source: https://habr.com/ru/post/1772322/


All Articles