加入doctrine symfony中的查询

时间:2010-03-18 07:41:55

标签: join symfony1 doctrine

我有两个表userdtails和博客问题架构是

UserDetails:
  connection: doctrine
  tableName: user_details
  columns:
    id:
      type: integer(8)
      fixed: false
    name:
      type: string(255)
      fixed: false

BlogQuestion:
  connection: doctrine
  tableName: blog_question
  columns:
    question_id:
      type: integer(8)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    blog_id:
      type: integer(8)
      fixed: false
    user_id:
      type: integer(8)
      fixed: false
    question_title:
      type: string(255)

我正在使用一个连接查询来检索这两个表中的所有问题和用户详细信息我的连接查询是

$q = Doctrine_Query::create()
    ->select('*')
    ->from('BlogQuestion u')
    ->leftJoin('u.UserDetails p');
    $q->execute();

但它显示此错误未知关系别名UserDetails

请任何人帮助我

提前致谢

1 个答案:

答案 0 :(得分:2)

为什么你没有在你的学说中建立关系?

UserDetails:
  connection: doctrine
  tableName: user_details
  columns:
    id:
      type: integer(8)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true

BlogQuestion:
  connection: doctrine
  tableName: blog_question
  columns:
    question_id:
      type: integer(8)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    blog_id:
      type: integer(8)
      fixed: false
    user_id:
      type: integer(8)
      fixed: false
    question_title:
      type: string(255)
  relations:
    UserDetails:
      local: user_id

你的yml中没有任何内容可以告诉你在离开加入时应该链接的内容。我自己构建它并且它确实有效