Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 1.2.3
-
Fix Version/s: None
-
Component/s: Query
-
Labels:None
-
Environment:Windows XP Pro. Service Pack 3, Eclipe PDT, Doctrine 1.2.3, Php 5.2.11
Description
i try to get all preferences with an IdUser specified.
schema.yml
UserHasPreference:
connection: hopscore
actAs:
I18n:
fields: [value]
Timestampable:
created:
name: created_at
type: timestamp
format: Y-m-d H:i:s
columns:
idUserHasPreference:
name: idUserHasPreference as id
type: integer(4)
unsigned: true
primary: true
autoincrement: true
UsersIdUser:
name: UsersIdUser as idUser
type: integer(4)
unsigned: true
notnull: true
PreferencesIdPreference:
name: PreferencesIdPreference as idPreference
type: integer(4)
unsigned: true
notnull: true
MatchLinksMatchLinkId:
name: MatchLinksMatchLinkId as MatchLinkId
type: integer(4)
unsigned: true
notnull: true
value:
type: string(100)
relations:
Users:
class: User
local: idUser
foreign: id
type: one
Preferences:
class: Preference
local: idPreference
foreign: id
type: one
MatchLinks:
class: MatchLink
local: MatchLinkId
foreign: id
type: one
options:
collate: utf8_unicode_ci
charset: utf8
Doctrine Request
$preferences = Doctrine_Query::create()
->select('uhp.idPreference as idPref')
->addSelect('uhpt.value as value')
->addSelect('uhp.MatchLinkId as idItem')
->from('UserHasPreference uhp')
->innerJoin('uhp.Translation uhpt')
->where('uhp.idUser = ?', intval($idUser))
->execute(array(), Doctrine::HYDRATE_ARRAY);
return $preferences;
With $preferences->getSqlQuery(); and getParams(); and report this SQL query in phpmydadmin.
With SQL i have 13 elements. But in my object $preference i have one element (Doctrine::HYDRATE_ARRAY)
With "Doctrine::HYDRATE_NONE", i have 13 elements as SQL query.
I have the same problem, and I think this is related to the select statement. It seems that a select statement where all fields are aliased will cause this behavior. A simple work-around is to select one field without aliasing it.
Code for reproducing / work-around:
$query = Doctrine_Query::create();
$query->from('Results r');
$query->select('p.id as myid, r.value as foo');
$query->innerJoin('r.Profil p on (r.pid=123)');
$results = $query->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
count($results) = 1
$query = Doctrine_Query::create();
$query->from('Results r');
$query->select('p.id as myid, r.value');
$query->innerJoin('r.Profil p on (r.pid=123)');
$results = $query->execute(array(), Doctrine_Core::HYDRATE_ARRAY);
count($results) = 250