我在Symfony 1.4中使用Doctrine 1.2。比方说,我有一个用户模型,它有一个配置文件。这些被定义为:在Doctrine的当前表中添加虚拟列?
用户:
- ID
- 用户名
- 密码
- created_at
- 的updated_at
资料:
- ID
- USER_ID
- FIRST_NAME
- 姓氏
- 地址
- 城市
- POSTAL_CODE
我通常会得到这样的数据:
$query = Doctrine_Query::create()
->select('u.id, u.username, p.first_name, p.last_name')
->from('User u')
->leftJoin('Profile p')
->where('u.username = ?', $username);
$result = $query->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
print_r($result);
这将输出类似如下:
Array (
"User" => Array (
"id" => 1,
"username" => "jschmoe"
),
"Profile" => Array (
"first_name" => "Joseph",
"last_name" => "Schmoe"
)
)
不过,我想为用户包括“虚拟”列(不知道这是正确的术语),使得从档案领域实际看起来像他们'是用户的一部分。换句话说,我会像向看到print_r的声明看起来更像:
Array (
"User" => Array (
"id" => 1,
"username" => "jschmoe",
"first_name" => "Joseph",
"last_name" => "Schmoe"
)
)
有没有办法无论是通过我的schema.yml文件,或通过我的Doctrine_Query对象做到这一点?
我对你的代码示例感到困惑......它看起来像你只是复制和粘贴了我在原始问题中写的东西,除非我错过了一些东西。 – 2011-02-03 20:36:17
使用`from`而不是`createQuery`是唯一的区别...但它看起来像你在某个时候改变了... – prodigitalson 2011-02-03 21:08:40