[DDC-1764] [GH-326] 2.1.x setDiscriminatorMap fix Created: 04/Apr/12  Updated: 27/Jul/14  Resolved: 07/Apr/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: 2.1.7, 2.2.2, 2.3
Security Level: All

Type: Bug Priority: Major
Reporter: Benjamin Eberlei Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

This issue is created automatically through a Github pull request on behalf of smatyas:

Url: https://github.com/doctrine/doctrine2/pull/326

Message:

Fixing a bug when calling setDiscriminatorMap from multiple sources (ie: from Events::loadClassMetadata and annotation).

http://www.doctrine-project.org/jira/browse/DDC-1763



 Comments   
Comment by Benjamin Eberlei [ 04/Apr/12 ]

A related Github Pull-Request [GH-327] was opened
https://github.com/doctrine/doctrine2/pull/327

Comment by Benjamin Eberlei [ 04/Apr/12 ]

A related Github Pull-Request [GH-328] was opened
https://github.com/doctrine/doctrine2/pull/328

Comment by Benjamin Eberlei [ 04/Apr/12 ]

A related Github Pull-Request [GH-328] was synchronize
https://github.com/doctrine/doctrine2/pull/328

Comment by Benjamin Eberlei [ 06/Apr/12 ]

A related Github Pull-Request [GH-328] was synchronize
https://github.com/doctrine/doctrine2/pull/328

Comment by Benjamin Eberlei [ 07/Apr/12 ]

A related Github Pull-Request [GH-327] was synchronize
https://github.com/doctrine/doctrine2/pull/327

Comment by Benjamin Eberlei [ 07/Apr/12 ]

A related Github Pull-Request [GH-328] was synchronize
https://github.com/doctrine/doctrine2/pull/328

Comment by Benjamin Eberlei [ 07/Apr/12 ]

A related Github Pull-Request [GH-327] was closed
https://github.com/doctrine/doctrine2/pull/327

Comment by Benjamin Eberlei [ 07/Apr/12 ]

A related Github Pull-Request [GH-328] was closed
https://github.com/doctrine/doctrine2/pull/328

Comment by Benjamin Eberlei [ 07/Apr/12 ]

A related Github Pull-Request [GH-326] was closed
https://github.com/doctrine/doctrine2/pull/326

Comment by Doctrine Bot [ 27/Jul/14 ]

A related Github Pull-Request [GH-328] was closed:
https://github.com/doctrine/common/pull/328





[DDC-1770] Select from multiple subclassed entities generates SQL syntax error Created: 05/Apr/12  Updated: 27/May/12  Resolved: 27/May/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: DQL
Affects Version/s: 2.1.6
Fix Version/s: 2.1.7
Security Level: All

Type: Bug Priority: Major
Reporter: Nicolas Laplante Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None
Environment:

Symfony 2.0.12
PHP 5.3.10
MySQL 5.1


Attachments: File Comment.php     File CommentHistoryItem.php     File HistoryItem.php     File Photo.php     File PhotoHistoryItem.php    

 Description   

I have 2 entities subclassing a "master" entity using single table inheritance:

HistoryItem:
createdAt datetime

PhotoHistoryItem extends HistoryItem
photo: (foreign key to Photo entity)

CommentHistoryItem extends HistoryItem
comment: (foreign key to Comment entity)

I want to select all of them using the following DQL:

SELECT p, c FROM ProFolioBundle:PhotoHistoryItem p, ProFolioBundle:CommentHistoryItem c LEFT JOIN p.photo LEFT JOIN c.comment

But the generated SQL has an error in the final AND syntax (it generates "AND AND"):

SELECT h0_.id AS id0, h0_.createdAt AS createdAt1, h1_.id AS id2, h1_.createdAt AS createdAt3, h0_.type AS type4, h1_.type AS type5 FROM HistoryItem h0_, HistoryItem h1_ LEFT JOIN Photo p2_ ON h0_.photo_id = p2_.id INNER JOIN Comment c3_ ON h1_.comment_id = c3_.id WHERE (h0_.type IN ('photo') AND AND h1_.type IN ('comment')) LIMIT 20

The error MySQL throws is:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND h1_.type IN ('comment')) LIMIT 20' at line 1



 Comments   
Comment by Nicolas Laplante [ 05/Apr/12 ]

Fix entity names

Comment by Fabio B. Silva [ 17/Apr/12 ]

Hi Nicolas

Could you attach your entities please ?

Comment by Nicolas Laplante [ 17/Apr/12 ]

Sure, here are the 3 entities

Comment by Nicolas Laplante [ 17/Apr/12 ]

Here are the referenced entities in case you need them too

Comment by Benjamin Eberlei [ 27/May/12 ]

Fixed





[DDC-1835] Cloning PersistentCollection affects internal collection of clone source Created: 24/May/12  Updated: 27/May/12  Resolved: 27/May/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.2
Fix Version/s: 2.1.7, 2.2.3
Security Level: All

Type: Bug Priority: Major
Reporter: Karsten Dambekalns Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

When a PersistentCollection (PC) is loaded and is cloned before it is initialized, anything that is already in that collection will be duplicated if the collection is initialized after it has been marked dirty. The cause is a too late clone operation on the internal (Array)Collection (AC) in the PC.

  1. PC is loaded, but not initialized. The internal AC is empty.
  2. PC is cloned. PC' calls initialize() in __clone()
  3. PC' fills AC (as that has not been cloned yet)
  4. PC' clones AC

As a result the AC in PC now contains elements, but PC still is uninitialized. If PC is afterwards initialized and dirty, the elements already in AC will be considered new and added again to the AC.

The effect will be constraint violations in join tables due to duplicate entries.

The clone method causing this has been introduced with commit 647bd2b2f295d2cbe7d0ee67f21be8a48bae3db5 on February 17th.



 Comments   
Comment by Karsten Dambekalns [ 24/May/12 ]

Test and fix: https://github.com/doctrine/doctrine2/pull/356





[DDC-1836] [GH-356] [DDC-1835] Fix clone side effects in PersistentCollection Created: 24/May/12  Updated: 27/May/12  Resolved: 27/May/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: 2.1.7, 2.2.3
Security Level: All

Type: Bug Priority: Major
Reporter: Benjamin Eberlei Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

This issue is created automatically through a Github pull request on behalf of kdambekalns:

Url: https://github.com/doctrine/doctrine2/pull/356

Message:



 Comments   
Comment by Benjamin Eberlei [ 27/May/12 ]

A related Github Pull-Request [GH-356] was closed
https://github.com/doctrine/doctrine2/pull/356





[DDC-1799] Doctrine's Reverse Engineering 1-n (one to many) association misunderstood as 1-1 (one to one) Created: 27/Apr/12  Updated: 27/May/12  Resolved: 27/May/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.1.6
Fix Version/s: 2.1.7, 2.2.3
Security Level: All

Type: Bug Priority: Critical
Reporter: simone adami Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None
Environment:

MAC OS X 10.6.8, Symfony 2.0.12, PHP 5.3.6, mysql server 5.5.9



 Description   

I found an odd behaviour of Doctrine's reverse engineering process, just create two simple tables tied by a simple 1-n relationship, take a look at the snap of the folowing SQL code:

    SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
    SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
    SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';
    
    DROP SCHEMA IF EXISTS `ACME` ;
    CREATE SCHEMA IF NOT EXISTS `ACME` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
    USE `ACME` ;
    
    -- -----------------------------------------------------
    -- Table `ACME`.`task`
    -- -----------------------------------------------------
    DROP TABLE IF EXISTS `ACME`.`task` ;
    
    CREATE  TABLE IF NOT EXISTS `ACME`.`task` (
      `id_task` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
      `description` VARCHAR(45) NULL ,
      PRIMARY KEY (`id_task`) )
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `ACME`.`tag`
    -- -----------------------------------------------------
    DROP TABLE IF EXISTS `ACME`.`tag` ;
    
    CREATE  TABLE IF NOT EXISTS `ACME`.`tag` (
      `id_tag` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
      `name` VARCHAR(50) NULL ,
      `task_id` INT UNSIGNED NOT NULL ,
      PRIMARY KEY (`id_tag`) ,
      INDEX `fk_tag_task` (`task_id` ASC) ,
      CONSTRAINT `fk_tag_task`
        FOREIGN KEY (`task_id` )
        REFERENCES `ACME`.`task` (`id_task` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    ENGINE = InnoDB;
    
    
    
    SET SQL_MODE=@OLD_SQL_MODE;
    SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
    SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

I have a Symfony2 netbeans project at

> /Applications/MAMP/htdocs/Acme

and from that location, according to

> http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html

in a terminal I did:

    $ ./../../bin/php/php5.3.6/bin/php app/console doctrine:mapping:convert yml ./src/Acme/TaskBundle/Resources/config/doctrine/ --from-database --force
    Processing entity "Tag"
    Processing entity "Task"
    
    Exporting "yml" mapping information to "/Applications/MAMP/htdocs/Acme/src/Acme/TaskBundle/Resources/config/doctrine"
    
    $ ./../../bin/php/php5.3.6/bin/php app/console doctrine:mapping:import Acme\TaskBundle yml
    Importing mapping information from "default" entity manager
      > writing /Applications/MAMP/htdocs/Acme/src/Acme/TaskBundle/Resources/config/doctrine/Tag.orm.yml
      > writing /Applications/MAMP/htdocs/Acme/src/Acme/TaskBundle/Resources/config/doctrine/Task.orm.yml
    
    $ ./../../bin/php/php5.3.6/bin/php app/console doctrine:generate:entities Acme\TaskBundle
    Generating entities for bundle "AcmeTaskBundle"
      > backing up Tag.php to Tag.php~
      > generating Acme\TaskBundle\Entity\Tag
      > backing up Task.php to Task.php~
      > generating Acme\TaskBundle\Entity\Task

The fact is that it only seems ok, because if you take a look at "Tag.orm.yml":

Tag.orm.yml
    Acme\TaskBundle\Entity\Tag:
      type: entity
      table: tag
      fields:
        idTag:
          id: true
          type: integer
          unsigned: false
          nullable: false
          column: id_tag
          generator:
            strategy: IDENTITY
        name:
          type: string
          length: 50
          fixed: false
          nullable: true
      oneToOne:
        task:
          targetEntity: Task
          cascade: {  }
          mappedBy: null
          inversedBy: null
          joinColumns:
            task_id:
              referencedColumnName: id_task
          orphanRemoval: false
      lifecycleCallbacks: {  }

It created a *oneToOne* relationship and not a *oneToMany* !

If you need any more confirmation, here are **Task.php** and **Tag.php**:

**Task.php**

Task.php
    <?php
    
    namespace Acme\TaskBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * Acme\TaskBundle\Entity\Task
     */
    class Task
    {
        /**
         * @var integer $idTask
         */
        private $idTask;
    
        /**
         * @var string $description
         */
        private $description;
    
    
        /**
         * Get idTask
         *
         * @return integer 
         */
        public function getIdTask()
        {
            return $this->idTask;
        }
    
        /**
         * Set description
         *
         * @param string $description
         */
        public function setDescription($description)
        {
            $this->description = $description;
        }
    
        /**
         * Get description
         *
         * @return string 
         */
        public function getDescription()
        {
            return $this->description;
        }
    }
Tag.php
***Tag.php***

    <?php
    
    namespace Acme\TaskBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * Acme\TaskBundle\Entity\Tag
     */
    class Tag
    {
        /**
         * @var integer $idTag
         */
        private $idTag;
    
        /**
         * @var string $name
         */
        private $name;
    
        /**
         * @var Acme\TaskBundle\Entity\Task
         */
        private $task;
    
    
        /**
         * Get idTag
         *
         * @return integer 
         */
        public function getIdTag()
        {
            return $this->idTag;
        }
    
        /**
         * Set name
         *
         * @param string $name
         */
        public function setName($name)
        {
            $this->name = $name;
        }
    
        /**
         * Get name
         *
         * @return string 
         */
        public function getName()
        {
            return $this->name;
        }
    
        /**
         * Set task
         *
         * @param Acme\TaskBundle\Entity\Task $task
         */
        public function setTask(\Acme\TaskBundle\Entity\Task $task)
        {
            $this->task = $task;
        }
    
        /**
         * Get task
         *
         * @return Acme\TaskBundle\Entity\Task 
         */
        public function getTask()
        {
            return $this->task;
        }
    }

linuxatico



 Comments   
Comment by simone adami [ 30/Apr/12 ]

This problem is encountered only in this case, 1-1 and n-m relationship are handled in the right way, has anyone else faced this problem too?

linuxatico

Comment by simone adami [ 07/May/12 ]

Hi all,
I wanna give the Doctrine community my full support to help fixing this bug, but I need someone who can give me an answer.....
I couldn't figure out in the source code which is the method executed when given the command

$ ./../../bin/php/php5.3.6/bin/php app/console doctrine:mapping:convert yml ./src/Acme/TaskBundle/Resources/config/doctrine/ --from-database --force

I will keep on looking for it, but some help will be appreciated,

linuxatico

Comment by simone adami [ 07/May/12 ]

Found in vendor/doctrine/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php
I'll see what I can do.

linuxatico

Comment by simone adami [ 09/May/12 ]

Even if I keep being ignored, I want to report a very useful discovery about this annoying bug: it's 100% related to the YAML conversion, because if you execute the first command

 $ ./../../bin/php/php5.3.6/bin/php app/console doctrine:mapping:convert xml ./src/Acme/TaskBundle/Resources/config/doctrine/ --from-database --force

Using XML instead of YML it works in the expected way. I wonder if the author of this code have written a unit test before integrating this function in the official release of Doctrine.... (ironic question)

linuxatico

Comment by Benjamin Eberlei [ 27/May/12 ]

This case was indeed not unit-tested, many-to-one and one-to-one were handled the same in YAML Exporter. No need to get picky about it though, we are investing our free time here.





[DDC-1801] PostgreSQL - quoting identifiers also quotes aliases Created: 29/Apr/12  Updated: 29/Apr/12  Resolved: 29/Apr/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.1.6
Fix Version/s: 2.1.7
Security Level: All

Type: Bug Priority: Major
Reporter: ross neacoders Assignee: Benjamin Eberlei
Resolution: Duplicate Votes: 0
Labels: None
Environment:

Symfony2



 Description   

First of all, I fully agree with Roman Borshell's concept that if you want identifier to be quoted you need to do it manually in Entity by back-ticking ` ` it.

That's what I did:

    /**
     * @var string $name
     *
     * @ORM\Column(name="`Name`", type="string", length=50, nullable=false)
     */
    private $name;

    /**
     * @var string $surname
     *
     * @ORM\Column(name="`Surname`", type="string", length=50, nullable=false)
     */
    private $surname;

But when I ran a simple query

        $qb = $repository->createQueryBuilder('p');
        $query = $qb
        ->select('p.name, p.surname, p.photographerguid')
        ->where("p.name = 'Peter'");
        
        echo $query->getQuery()->getSQL();

what I get is TERRIBLE output

SELECT p0_."Name" AS "Name"0, p0_."Surname" AS "Surname"1, p0_."PhotographerGUID" AS "PhotographerGUID"2 FROM "Photographers" p0_ WHERE p0_."Name" = 'Peter' 

It also quoted identifiers like "Surname"1, "Name"0.

I spent 3 hours digging your code, and finally found in Doctrine\ORM\Query\SqlWalker.php Ln: 969

                $columnName = $class->getQuotedColumnName($fieldName, $this->_platform);

                $columnAlias =  $this->getSQLColumnAlias($columnName);

You quote column and then pass it to getSQLColumnAlias which appends some number to the end.

Is there a fix already in newer versions? Where can i find it then - will definitely make a port to this one.



 Comments   
Comment by ross neacoders [ 29/Apr/12 ]

Duplicate of DDC-1695
(will report there)





[DDC-1745] [GH-316] Fixes autoloading of generated Annotations Created: 01/Apr/12  Updated: 16/Apr/12  Resolved: 16/Apr/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: 2.1.7, 2.2.3
Security Level: All

Type: Bug Priority: Major
Reporter: Benjamin Eberlei Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

This issue is created automatically through a Github pull request on behalf of fixe:

Url: https://github.com/doctrine/doctrine2/pull/316

Message:

This PR fixes an [issue](https://github.com/symfony/symfony/issues/3752) submited by @Venzon.



 Comments   
Comment by Benjamin Eberlei [ 01/Apr/12 ]

A related Github Pull-Request [GH-316] was synchronize
https://github.com/doctrine/doctrine2/pull/316

Comment by Benjamin Eberlei [ 04/Apr/12 ]

A related Github Pull-Request [GH-316] was synchronize
https://github.com/doctrine/doctrine2/pull/316

Comment by Benjamin Eberlei [ 06/Apr/12 ]

A related Github Pull-Request [GH-316] was synchronize
https://github.com/doctrine/doctrine2/pull/316

Comment by Benjamin Eberlei [ 07/Apr/12 ]

A related Github Pull-Request [GH-316] was synchronize
https://github.com/doctrine/doctrine2/pull/316

Comment by Benjamin Eberlei [ 16/Apr/12 ]

Fixed





[DDC-1763] Fixing a bug when calling setDiscriminatorMap from multiple sources (ie: from Events::loadClassMetadata and annotation). Created: 04/Apr/12  Updated: 07/Apr/12  Resolved: 07/Apr/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.1.6, 2.2, Git Master
Fix Version/s: 2.1.7, 2.2.2, 2.3
Security Level: All

Type: Bug Priority: Major
Reporter: Matyas Somfai Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 1
Labels: None


 Description   

We tried to set discriminator map in https://github.com/Netpositive/NetpositiveDiscriminatorMapBundle both from Events::loadClassMetadata and annotation.

Pull request created on 2.1.x, 2.2, master branches.



 Comments   
Comment by Peter Buri [ 05/Apr/12 ]

Pull requests:

https://github.com/doctrine/doctrine2/pull/326
https://github.com/doctrine/doctrine2/pull/327
https://github.com/doctrine/doctrine2/pull/328





[DDC-1648] Primary Keys as Foreign Keys - still not working in Reverse Engineering in 2.1.6 Created: 12/Feb/12  Updated: 14/Mar/12  Resolved: 14/Mar/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.1.6
Fix Version/s: 2.1.7, 2.2.2
Security Level: All

Type: Bug Priority: Major
Reporter: ross neacoders Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

Please, read this old thread - looks like this problem still is not solved

http://comments.gmane.org/gmane.comp.php.symfony.symfony2/1398

>>The primary key as foreign key limitation is from the 2.0 manual. You are using 2.1 with symfony, which supports this. Please use the correct manual.

>> The only problem is that the reverse engineering does not support this. You have to reverse engineer yourself, or write a patch to have Doctrine support this. I would really appreciate it

As I understand it is supported in the "core", but some reverse engineer script is still not using that possibility.
Could you at least point where this can fixed?



 Comments   
Comment by Benjamin Eberlei [ 12/Feb/12 ]

In lib/Doctrine/ORM/Mapping/DatabaseDriver.php

Comment by ross neacoders [ 12/Feb/12 ]

Thank you Benjamin,

Actually started tracking this error from /lib/Doctrine/ORM/Mapping/ClasMetadataInfo.php and step-bystep it goes to
/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php

Actually it calls ClasMetadataInfo::mapMayToOne instead of mapOneToOne in such situations.
Will investigate further. Pff... DatabaseDriver.php looks a hard class.

Comment by ross neacoders [ 12/Feb/12 ]

I am almost done with it - need a little more help from you:

So I fixed the DatabaseDriver so it correctly calls mapOneToOne
and passes association_mapping to it.

    /**
     * Adds a one-to-one mapping.
     *
     * @param array $mapping The mapping.
     */
    public function mapOneToOne(array $mapping)
    {
        $mapping['type'] = self::ONE_TO_ONE;
        $mapping = $this->_validateAndCompleteOneToOneMapping($mapping);
        $this->_storeAssociationMapping($mapping);
print_r($assocMapping); <--added this to see what structure we have on output
    }

this gives the following structure

Array
(
    [fieldName] => someguid                      <--- my primary key field, which is also foreign key
    [targetEntity] => Additionalinfo               <--- target table
    [id] => 1                                                      <--- indicates that this mapping is also id (primary key)
    [joinColumns] => Array
        (
            [0] => Array
                (
                    [name] => Someguid                                                     <--- join columns
                    [referencedColumnName] => UniqueID                    
                )

        )

    [type] => 1  <-- indicates ONE-TO-ONE assoc mapping
    [mappedBy] => 
    [inversedBy] => 
    [isOwningSide] => 1
    [sourceEntity] => Sampledata
    [fetch] => 2
..... (i omit other data as not important)
)

Now the problem: in my entity I got the following

    /**
     * @var Additionalinfo
     *
     * @ORM\OneToOne(targetEntity="Additionalinfo")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="Someguid", referencedColumnName="UniqueID")
     * })
     */
    private $someguid;

So it correctly created a One-To-One mapping, but it did not preserve @Id attribute.

I guess this is because field_associations and mapping_associations are processed in separate way,
and in mapping_association it ignores the $mapping["id"] setting.

Do you know what code is managing creating the <id ....> / @Id staff - it is common for annotation/yaml/xml, e.x. when i generated xml for entity, it also does not contain <id > tag.

Comment by ross neacoders [ 12/Feb/12 ]

Update: fixed the last problem in Doctrine/ORM/Tools/EntityGenerator.php

Still has to be fixed in YAML/XML exporters - not very familiar with the syntax.

Comment by Benjamin Eberlei [ 03/Mar/12 ]

This PR fixes the problem https://github.com/doctrine/doctrine2/pull/280

Comment by Benjamin Eberlei [ 14/Mar/12 ]

Fixed





[DDC-1683] Doctrine\ORM\Query\Expr\Comparison Doesn't handle boolean values properly Created: 06/Mar/12  Updated: 14/Mar/12  Resolved: 14/Mar/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: DQL, ORM
Affects Version/s: 2.1.6, 2.2
Fix Version/s: 2.1.7, 2.2.2
Security Level: All

Type: Bug Priority: Major
Reporter: Peter Mitchell Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None
Environment:

Symfony 2.0.11, MySQL, PDO, PHP Version 5.3.5-1ubuntu7.7



 Description   

Expected behaviour - Using boolean types in Query Builder

The following works

$qb = $this->getDoctrine()->getEntityManager()->createQueryBuilder();

$qb
    ->select('entity')
    ->from('FooBundle:Entity', 'entity')
    ->where($qb->expr()->eq('entity.visible', true))
;

$query = $qb->getQuery();

return $query->getResult();

The following throws an Doctrine/ORM/Query/QueryException error [Syntax Error] line 0, col -1: Error: Expected Literal, got end of string.

$qb = $this->getDoctrine()->getEntityManager()->createQueryBuilder();

$qb
    ->select('entity')
    ->from('FooBundle:Entity', 'entity')
    ->where($qb->expr()->eq('entity.visible', false))
;

$query = $qb->getQuery();

return $query->getResult();

This is due to Doctrine\ORM\Query\Expr\Comparison::_toString()

public function __toString()
{
    return $this->_leftExpr . ' ' . $this->_operator . ' ' . $this->_rightExpr;
}

When $this->_rightExpr === true type coercion results in 1, but for false it results in an empty string, thus
resulting in invalid SQL.

The following in Doctrine\ORM\Query\Expr\Comparison::__construct() resolves the problem (https://github.com/doctrine/doctrine2/pull/297)

public function __construct($leftExpr, $operator, $rightExpr)
{
    $this->_leftExpr  = $leftExpr;
    $this->_operator  = $operator;
    $this->_rightExpr = $rightExpr === false ? (int) $rightExpr : $rightExpr;
}

Could be related to http://www.doctrine-project.org/jira/browse/DDC-1048 and http://www.doctrine-project.org/jira/browse/DDC-949



 Comments   
Comment by Benjamin Eberlei [ 14/Mar/12 ]

Fixed, but your code is wrong. It has to be

$qb->expr()->literal(true);




[DDC-1695] SQLs for PostgreSQL case sensite tables/fields are wrongly generated Created: 09/Mar/12  Updated: 11/Mar/12  Resolved: 11/Mar/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.1.6
Fix Version/s: 2.1.7, 2.2.2
Security Level: All

Type: Bug Priority: Blocker
Reporter: Ignacio Larranaga Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None
Environment:

PostgreSQL 9.x, Symfony 2


Attachments: Text File doctrine-2.1.6.patch     Text File SqlWalker.patch    

 Description   

The SQLs for case sensitive schemas in postgreSQL are wronly generated.

Example:
Schema:

CREATE TABLE "News" (
  "IdNews" serial NOT NULL,
  "IdUser" bigint NOT NULL,
  "IdLanguage" integer NOT NULL,
  "IdCondition" integer,
  "IdHealthProvider" integer,
  "IdSpeciality" integer,
  "IdMedicineType" integer,
  "IdTreatment" integer,
  "Title" character varying,
  "SmallText" character varying,
  "LongText" character varying,
  "PublishDate" timestamp with time zone,
  "IdxNews" tsvector,
  "Highlight" boolean NOT NULL DEFAULT false,
  "Order" integer NOT NULL DEFAULT 0,
  "Deleted" boolean NOT NULL DEFAULT false,
  "Active" boolean NOT NULL DEFAULT false,
  "UpdateToHighlighted" boolean DEFAULT false,
  CONSTRAINT "News_pkey" PRIMARY KEY ("IdNews" ));

Object (I added quotes trying to generate the SQLs quoted.:

<?php

namespace GlobalTreatments\ApplicationBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="""News""")
 * @ORM\Entity
 */
class News
{
    /**
     * @var integer $idNews
     *
     * @ORM\Column(name="""IdNews""", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="SEQUENCE")
     * @ORM\SequenceGenerator(sequenceName="""News_IdNews_seq""", allocationSize="1", initialValue="1")
     */
    private $idNews;

    /**
     * @var bigint $iduser
     *
     * @ORM\Column(name="""IdUser""", type="bigint", nullable=false)
     */
    private $idUser;

    /**
     * @var integer $idLanguage
     *
     * @ORM\Column(name="""IdLanguage""", type="integer", nullable=false)
     */
    private $idLanguage;

    /**
     * @var integer $idCondition
     *
     * @ORM\Column(name="""IdCondition""", type="integer", nullable=true)
     */
    private $idCondition;

    /**
     * @var integer $idHealthProvider
     *
     * @ORM\Column(name="""IdHealthProvider""", type="integer", nullable=true)
     */
    private $idHealthProvider;

    /**
     * @var integer $idSpeciality
     *
     * @ORM\Column(name="""IdSpeciality""", type="integer", nullable=true)
     */
    private $idSpeciality;

    /**
     * @var integer $idMedicineType
     *
     * @ORM\Column(name="""IdMedicineType""", type="integer", nullable=true)
     */
    private $idMedicineType;

    /**
     * @var integer $idTreatment
     *
     * @ORM\Column(name="""IdTreatment""", type="integer", nullable=true)
     */
    private $idTreatment;

    /**
     * @var string $title
     *
     * @ORM\Column(name="""Title""", type="string", nullable=true)
     */
    private $title;

    /**
     * @var string $smallText
     *
     * @ORM\Column(name="""SmallText""", type="string", nullable=true)
     */
    private $smallText;

    /**
     * @var string $longText
     *
     * @ORM\Column(name="""LongText""", type="string", nullable=true)
     */
    private $longText;

    /**
     * @var datetimetz $publishDate
     *
     * @ORM\Column(name="""PublishDate""", type="datetimetz", nullable=true)
     */
    private $publishDate;

    /**
     * @var tsvector $idxNews
     *
     * @ORM\Column(name="""IdxNews""", type="tsvector", nullable=true)
     */
    private $idxNews;

    /**
     * @var boolean $highlight
     *
     * @ORM\Column(name="""Highlight""", type="boolean", nullable=false)
     */
    private $highlight;

    /**
     * @var integer $order
     *
     * @ORM\Column(name="""Order""", type="integer", nullable=false)
     */
    private $order;

    /**
     * @var boolean $deleted
     *
     * @ORM\Column(name="""Deleted""", type="boolean", nullable=false)
     */
    private $deleted;

    /**
     * @var boolean $active
     *
     * @ORM\Column(name="""Active""", type="boolean", nullable=false)
     */
    private $active;

    /**
     * @var boolean $updateToHighlighted
     *
     * @ORM\Column(name="""UpdateToHighlighted""", type="boolean", nullable=true)
     */
    private $updateToHighlighted;

    /**
     * @var condition
     *
     * @ORM\ManyToOne(targetEntity="Condition")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="""IdCondition""", referencedColumnName="""IdCondition""")
     * })
     */
    private $condition;

    /**
     * @var healthProvider
     *
     * @ORM\ManyToOne(targetEntity="HealthProvider")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="""IdHealthProvider""", referencedColumnName="""IdHealthProvider""")
     * })
     */
    private $healthProvider;

    /**
     * @var language
     *
     * @ORM\ManyToOne(targetEntity="Language")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="""IdLanguage""", referencedColumnName="""IdLanguage""")
     * })
     */
    private $language;

    /**
     * @var medicineType
     *
     * @ORM\ManyToOne(targetEntity="MedicineType")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="""IdMedicineType""", referencedColumnName="""IdMedicineType""")
     * })
     */
    private $medicineType;

    /**
     * @var speciality
     *
     * @ORM\ManyToOne(targetEntity="Speciality")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="""IdSpeciality""", referencedColumnName="""IdSpeciality""")
     * })
     */
    private $speciality;

    /**
     * @var treatment
     *
     * @ORM\ManyToOne(targetEntity="Treatment")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="""IdTreatment""", referencedColumnName="""IdTreatment""")
     * })
     */
    private $treatment;

    /**
     * @var user
     *
     * @ORM\ManyToOne(targetEntity="User")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="""IdUser""", referencedColumnName="""IdUser""")
     * })
     */
    private $user;

    ....

}

DQL:

'SELECT n.smallText, n.publishDate ' .
'FROM News n ' .
	'INNER JOIN n.language la ' .
'WHERE la.languageCode = :languageCode ' .
'ORDER BY n.publishDate DESC'

Generated SQL:

SELECT "0_."SmallText" AS "SmallText"0, "0_."PublishDate" AS "PublishDate"1 FROM "News" "0_ INNER JOIN "Language" "1_ ON "0_."IdLanguage" = "1_."IdLanguage" WHERE "1_."LanguageCode" = ? ORDER BY "0_."PublishDate" DESC LIMIT 6

Notice there are unmattched " in the SQL.



 Comments   
Comment by Ignacio Larranaga [ 09/Mar/12 ]

If there is another approach to specify the table/column names are case sensitive in PGSQL please let me know.

Comment by Ignacio Larranaga [ 09/Mar/12 ]

Just to comment. I also tried the normal quoting.

Example: @ORM\Column(name="`IdNews`", type="integer", nullable=false)

And does not work too because of the same reason.

Comment by Ignacio Larranaga [ 09/Mar/12 ]

Hi, I generate this patch and seems to be working for me (at least what I'm testing right now).

I used ยด to quote tables and single attributes (not relationships) and the SQLs are correctly generated.

Comment by Ignacio Larranaga [ 09/Mar/12 ]

Adding a new patch for another files I need to change.

Comment by Benjamin Eberlei [ 11/Mar/12 ]

Formatted code

Comment by Benjamin Eberlei [ 11/Mar/12 ]

Fixed and merged into 2.1.x and 2.2 branches





[DDC-1678] When many to many changes but no fields, listeners don't get notified about update. Created: 03/Mar/12  Updated: 03/Mar/12  Resolved: 03/Mar/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.2
Fix Version/s: 2.1.7, 2.2.1
Security Level: All

Type: Bug Priority: Major
Reporter: Benjamin Eberlei Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

See https://github.com/doctrine/doctrine2/pull/256



 Comments   
Comment by Benjamin Eberlei [ 03/Mar/12 ]

Fixed





[DDC-1659] Clear read only entities Created: 19/Feb/12  Updated: 20/Feb/12  Resolved: 20/Feb/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: 2.1.7, 2.2.1
Security Level: All

Type: Bug Priority: Major
Reporter: Benjamin Eberlei Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

https://github.com/doctrine/doctrine2/pull/286



 Comments   
Comment by Benjamin Eberlei [ 20/Feb/12 ]

Fixed





[DDC-1643] PersistentCollection should support clone Created: 09/Feb/12  Updated: 17/Feb/12  Resolved: 17/Feb/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.2
Fix Version/s: 2.1.7, 2.2.1
Security Level: All

Type: Bug Priority: Major
Reporter: Bernhard Schussek Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

I'm trying to clone a PersistentCollection and expect to get a stable snapshot. But the class does not implement __clone, thus both objects refer to the same internal ArrayCollection.

I can't use takeSnapshot because I'm writing generic code that should work with any implementation of Traversable/ArrayAccess.



 Comments   
Comment by Benjamin Eberlei [ 09/Feb/12 ]

Moved to right project

Comment by Bernhard Schussek [ 10/Feb/12 ]

Thank you for moving. Any comments on the feasibility of this issue?

Comment by Benjamin Eberlei [ 10/Feb/12 ]

I guess its feasible, i have to think about:

1. how to fix the issue
2. what behavior to attach in general.

Comment by Bernhard Schussek [ 10/Feb/12 ]

Ok. For the sake of completeness, this issue directly causes another in Symfony2 which was already partially fixed here: https://github.com/symfony/symfony/pull/3315

Comment by Josiah [ 13/Feb/12 ]

PR submitted for this issue: https://github.com/doctrine/doctrine2/pull/281

Comment by Benjamin Eberlei [ 17/Feb/12 ]

What are you doing after the PersistentCollection is cloned?

The reason is, that if the code looks like this:

$col = clone $entity->getCol();
$otherEntity->setCol($col);
echo count($col);
$em->flush();

It will do very weird stuff using the owner of the association $col which is $entity. It will also try to insert the $col for $entity not for $otherEntity. To prevent this we have to do some work,

Comment by Benjamin Eberlei [ 17/Feb/12 ]

Fixed in https://github.com/doctrine/doctrine2/commit/93f79d0810a158138020b4cca3332f9f0b1a76af and merged into 2.2 and 2.1.x





[DDC-1638] Inexistant method newInstance in UnitOfWork Created: 07/Feb/12  Updated: 10/Feb/12  Resolved: 10/Feb/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.1.6
Fix Version/s: 2.1.7
Security Level: All

Type: Bug Priority: Critical
Reporter: Christophe Coevoet Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

the UnitOfWork uses ``newInstance`` to get the managed copy but this method does not exist in 2.1.6, thus breaking the code: https://github.com/doctrine/doctrine2/blob/e1647229cd2544bd77f10620e1b95a5781c4a733/lib/Doctrine/ORM/UnitOfWork.php#L1418

This is probably an error when backporting a patch as the method exists in master



 Comments   
Comment by Marco Pivetta [ 07/Feb/12 ]

Patch at https://github.com/doctrine/doctrine2/pull/276

Comment by Benjamin Eberlei [ 10/Feb/12 ]

Fixed





Generated at Mon Jul 28 10:36:18 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.