1
0
mirror of synced 2025-02-20 06:03:15 +03:00

branch for DDC-1335

This commit is contained in:
Fabio B. Silva 2011-09-23 18:10:58 -03:00
parent 9795cb1f0d
commit f4c5c4ba01
3 changed files with 95 additions and 7 deletions

View File

@ -34,27 +34,54 @@ namespace Doctrine\ORM\Query\Expr;
*/
class From
{
/**
* @var string
*/
private $_from;
/**
* @var string
*/
private $_alias;
public function __construct($from, $alias)
/**
* @var string
*/
private $_indexBy;
/**
* @param string $from The class name.
* @param string $alias The alias of the class.
* @param string $indexBy The index for the from.
*/
public function __construct($from, $alias, $indexBy = null)
{
$this->_from = $from;
$this->_alias = $alias;
$this->_from = $from;
$this->_alias = $alias;
$this->_indexBy = $indexBy;
}
/**
* @return string
*/
public function getFrom()
{
return $this->_from;
}
/**
* @return string
*/
public function getAlias()
{
return $this->_alias;
}
/**
* @return string
*/
public function __toString()
{
return $this->_from . ' ' . $this->_alias;
return $this->_from . ' ' . $this->_alias . ($this->_indexBy ? ' INDEX BY ' . $this->_indexBy : '');
}
}

View File

@ -595,9 +595,10 @@ class QueryBuilder
*
* @param string $from The class name.
* @param string $alias The alias of the class.
* @param string $indexBy The index for the from.
* @return QueryBuilder This QueryBuilder instance.
*/
public function from($from, $alias)
public function from($from, $alias,$indexBy = null)
{
return $this->add('from', new Expr\From($from, $alias), true);
}

View File

@ -0,0 +1,60 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use DateTime;
require_once __DIR__ . '/../../../TestInit.php';
class DDC1135Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
$classes = array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1135User')
);
try {
$this->_schemaTool->dropSchema($classes);
$this->_schemaTool->createSchema($classes);
} catch(\Exception $e) {
}
}
public function testTicket()
{
$this->markTestIncomplete();
$builder = $this->_em->createQueryBuilder();
$builder->select('u')->from('Doctrine\Tests\ORM\Functional\Ticket\DDC1135User', 'u', 'u.id');
$sql = $builder->getQuery()->getSQL();
$this->assertEquals('SELECT d0_.id AS id0, d0_.name AS name1 FROM DDC1135User INDEX BY d0_.id', $sql);
}
}
/**
* @Entity
*/
class DDC1135User
{
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
protected $id;
/**
* @Column(type="string", length=255)
*/
protected $name;
}