Zendcasts Forum

A community of developers who work with the Zend Framework and other enterprise PHP technologies

You are not logged in.

#1 2010-06-05 22:58:00

blackcat
New member
Registered: 2010-06-05
Posts: 1

Zend + Doctrine + Left Join

Hi!

Can you please help? I would like to write a query. But the doctrine will generate incorrect code, and I do not understand why.


#schema.yml:

Car:
  connection: doctrine
  tableName: car
  columns:
    id:
      type: integer(8)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    brand:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
  relations:
    Users:
      local: id
      foreign: car_id
      type: many
      class: User
User:
  connection: doctrine
  tableName: user
  columns:
    id:
      type: integer(8)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    name:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    email:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    phone:
      type: string(9)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    car_id:
      type: integer(8)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
  relations:
    Car:
      local: car_id
      foreign: id
      type: one

#index.phtml

$q = Doctrine_Query::create()
    ->select('id,brand')
    ->from('Model_User u')
    ->leftJoin('Model_Car c');

echo $q->getSqlQuery(); 

#firefox output

SELECT u.id AS u__id, u.brand AS u__brand FROM user u, car c




#From Doctrine documentation:

// test.php

// ...

$q = Doctrine_Query::create()
    ->select('u.username, p.*')
    ->from('User u')
    ->leftJoin('u.Phonenumbers p')

echo $q->getSqlQuery();

the above call to getSql() would output the following SQL query:

SELECT
u.id AS u__id,
u.username AS u__username,
p.id AS p__id,
p.user_id AS p__user_id,
p.phonenumber AS p__phonenumber
FROM user u
LEFT JOIN phonenumber p ON u.id = p.user_id

What could be the reason that I can not generate this type of code?

Offline

#2 2010-07-21 21:55:35

TimSchofield
New member
Registered: 2010-07-21
Posts: 2

Re: Zend + Doctrine + Left Join

try

$q = Doctrine_Query::create()
    ->select('u.id,u.name,c.*')
    ->from('Model_User u')
    ->leftJoin('u.Car c');

echo $q->getSqlQuery();

Offline

Board footer

Powered by FluxBB