views:

797

answers:

1

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:
      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

+1  A: 

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

plod
Thanks but when iam running symfony doctrine:build --all --no-confirmationIt shoeing an error Invalid schema element named "Local" at path BlogQuestion->columns->UserDetails
THOmas
sorry THOmas i am a little tired I have corrected it
plod
Then also it showing the same errorInvalid schema element named "Local" at path BlogQuestion->columns->UserDetails
THOmas
wait 20 minutes, I will check my code in the office, although i have removed the upper case "L" with a lower case "l" above. You may also need to set id in UserDetails as a primary key.
plod
UserDetails:connection: doctrine tableName: user_details columns: id: type: integer(8) fixed: false unsigned: false primary: true autoincrement: true autoincrement: true
THOmas
Hello THOmas, I have just built my new version I have edited above, and it does work. (now to remove it before i deploy :))
plod
Now the query is working fine but iam getting the fields from the BlogQuestion only$this->questions = Doctrine_Query::create() ->select('user_id') ->from('BlogQuestion u') ->leftJoin('u.UserDetails p') ->execute();
THOmas
The generated query is SELECT b.question_id AS b__question_id, b.user_id AS b__user_id FROM blog_question b LEFT JOIN user_details u ON b.user_id = u.id
THOmas