开发者

Join query in doctrine symfony

I have two tables userdetails and blog question The schema is

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:
开发者_如何学C      type: integer(8)
      fixed: false
    user_id:
      type: integer(8)
      fixed: false
    question_title:
      type: string(255)

I am using one join query for retrieving all the questions and user details from this two tables My join query is

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

But it is showing this error Unknown relation alias UserDetails

Pls anybody help me

Thanks in advance


why have you not set up a relationship in your doctrine?

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

there is nothing in your yml to tell doctrine what it should be linking on when you left join. I have just build this myself and it does work

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜