Doctrine select statement always returns all table fields

I have the following table

Test:
    tableName: test
    columns:
        test_id:
            name: test_id as id
            primary: true
            autoincrement: true
            type: integer
            notnull: true
        test_name:
            name: test_name as name
            type: string(255)
        test_title:
            name: test_title as title
            type: string(255)

and this dql statement

$dql = Doctrine_Query::create()->select('t.name')->from('Model_Test t');

next sql ist generated

SELECT t.test_id AS t__test_id, t.test_name AS t__test_name FROM test t

but after receiving the result in the doctrine, I have access to the header field, even if it is not selected:

foreach ($results as $result) {
    foreach ($result as $filed => $value) {
        echo "$filed => $value <hr>"; // echoes 'title' => null but title in db has other value
    }                                
}                                

also dump via Zend_Debug :: dump ($ results-> toArray ()); shows me all the fields, as if I made a choice *

So, how to limit the returned fields according to my choice?

Thanks in advance

Martin

+3
source share
3 answers

I think:

because

$results = $dql->execute();

retrieves the result as an object, non-selected vars are filled with zeros

then

$results = $dql->fetchArray(); 

selects an array, and in this case only the selected fields appear (except for the primary key)

+3
source

:

$events = Doctrine_Query::create()
     ->select("e.id, e.Title, e.Lat, e.Lon, e.Startdate, e.Location, e.Url")
     ->from('Event e')
     ->setHydrationMode(Doctrine::HYDRATE_ARRAY)
     ->execute();

+1

, , doctrine id name, title, , title . , ( SELECT * ).

- Doctrine - , , , foreach.

, ...

, $query->execute(Doctrine::HYDRATE_ARRAY), .

0

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


All Articles