[DDC-2531] ManyToManyPersister does not take Custom Types into account Created: 26/Jun/13  Updated: 07/May/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.3, 2.4, 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: George van Vliet Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 2
Labels: None


 Description   

When two entities, both using a custom type for the "@Id" column, have a "@ManyToMany" (bidirectional) relationship, the ManyToManyPersister does not take into account the custom type of the referenced id columns and therefore does not convert the values using the appropriate "convertToDatabaseValue" function.

The entities themselves are saved propery, but the insertion into the join table always fails.



 Comments   
Comment by Ben Getsug [ 07/May/15 ]

My scenario:

  • EntityA uses a custom type for its @Id column (specifically so I can store UUIDs in a binary column...see DDC-3721)
  • EntityA has a (unidirectional) many-to-many association with EntityB, and the usual ArrayCollection initialization on the property
  • I clear the entire collection by calling ArrayCollection::clear()
  • I call EntityManager::flush()
  • No errors occur, but no rows actually get deleted from the database.

Through debugging, I found that ManyToManyPersister::getDeleteSQL() does not handle custom types like ManyToManyPersister::getDeleteRowSQL() or ManyToManyPersister::removeElement(). So the proper SQL DELETE statement doesn't get executed.

My current workaround is to loop through my collection of EntityB, calling ArrayCollection::removeElement() with each entity. Given the complexity of ManyToManyPersister, I'm a bit leery of attempting a fix and submitting a PR, but at least wanted to document my issue here.





[DDC-3220] Association mappings of embedded class not loaded into entity classMetadata Created: 21/Jul/14  Updated: 06/May/15

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

Type: Bug Priority: Major
Reporter: Anatolie Marinescu Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 1
Labels: embeddables


 Description   

method inlineEmbeddable from Doctrine\ORM\Mapping\ClassMetadataInfo mapped only columns, but relations is omitted






[DDC-3727] [GH-1402] AbstractCommand: use name of helper, do not require alias Created: 05/May/15  Updated: 05/May/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

Name for the helper is "entityManager", see https://github.com/doctrine/doctrine2/blob/330f88e44ba0e5e6f932a92ae63b64cdd5cdc046/lib/Doctrine/ORM/Tools/Console/Helper/EntityManagerHelper.php#L70

Using "em" forces creating an alias.

Seems like some forgotten name change.






[DDC-3725] [GH-1400] pgsql and mysqli are supported by HHVM Created: 04/May/15  Updated: 04/May/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:






[DDC-3724] Resolve target entity also in discriminator map: does not work with non-alphabetical order Created: 04/May/15  Updated: 04/May/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Mapping Drivers
Affects Version/s: 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Minor
Reporter: Alan Poulain Assignee: Marco Pivetta
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Using a discriminator map and interfaces lead to an exception when there are not in alphabetical order.
For example,

/**
 * @ORM\DiscriminatorMap({
 *     "a" = "AEntityInterface",
 *     "b" = "BEntityInterface"
 * })
 */

is working but,

/**
 * @ORM\DiscriminatorMap({
 *     "b" = "BEntityInterface",
 *     "a" = "AEntityInterface"
 * })
 */

lead to:

[Doctrine\Common\Persistence\Mapping\MappingException]
Class 'BEntityInterface' does not exist






[DDC-3719] Criteria won't work on non-owning side of many to many collection Created: 29/Apr/15  Updated: 03/May/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Lazy Loading, ORM
Affects Version/s: Git Master
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Logan Bailey Assignee: Guilherme Blanco
Resolution: Unresolved Votes: 1
Labels: many-to-many, orm

Issue Links:
Reference
is referenced by DDC-3723 [GH-1399] Fix for DDC-3719. Open

 Description   

I received the following error when trying to call matching on a ManyToMany relationship from the non-owning side.

ErrorException in ManyToManyPersister.php line 234: Undefined index: relationToSourceKeyColumns

ManyToManyPersister::loadCriteria relies on the relationToSourceKeyColumns data from the mapping data. This value is set in ClassMetadataInfo::_validateAndCompleteManyToManyMapping, but it's only set on the owning side of the relationship.






[DDC-3723] [GH-1399] Fix for DDC-3719. Created: 03/May/15  Updated: 03/May/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Reference
relates to DDC-3719 Criteria won't work on non-owning sid... Open

 Description   

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

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

Message:

Switch to relationToTargetKeyColumns when matching non-owning side with Criteria. Fixes DDC-3719.






[DDC-3722] XmlExporter driver ignore entityListeners Created: 03/May/15  Updated: 03/May/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.4, 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Fedir Zinchuk Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: entityListeners, export, orm


 Description   

<entity-listeners> missed in XML export result, when export the entity mapping with entityListeners

And after quick look in the code, seems other drivers also ignore it






[DDC-3721] [GH-1398] When using a custom data type, SchemaTool does not pass column length field mapping to relation join columns Created: 29/Apr/15  Updated: 30/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Tools
Affects Version/s: 2.4, 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 1
Labels: None


 Description   

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

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

Message:

We have a custom data type for storing UUIDs in a BINARY column in MySQL:

class UuidType extends Type
{
    const UUID = 'uuid';


    /**
     * @inheritdoc
     */
    public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
    {
        return $platform->getBinaryTypeDeclarationSQL($fieldDeclaration);
    }


    /**
     * @inheritdoc
     */
    public function getName()
    {
        return self::UUID;
    }


    /**
     * @inheritdoc
     */
    public function convertToPhpValue($value, AbstractPlatform $platform)
    {
        if ($value !== null) {
            return strtoupper(bin2hex($value));
        }
    }


    /**
     * @inheritdoc
     */
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        if ($value !== null) {
            // If the app put any dashes in, we strip them, just in case
            return hex2bin(str_replace('-', '',$value));
        }
    }

    
    /**
     * @inheritdoc
     */
    public function requiresSQLCommentHint(AbstractPlatform $platform)
    {
        return true;
    }
    

    /**
     * Generate a UUID that is optimized for MySQL's InnoDB engine
     * Based on UUID1, but transposed for more optimal inserts and sized for binary(16) column
     *
     * @return string MySQL-optimized UUID that works well with UUID column type
     */
    public static function generateUuid()
    {
        $uuid = Uuid::uuid1()->toString();

        $uuidFormattedForMySQL = self::transposeUuid($uuid);

        return $uuidFormattedForMySQL;
    }


    /**
     * Optimize format of UUID for storing as binary in MySQL
     *
     * @param $uuid
     *
     * @return string
     *
     * @see http://www.percona.com/blog/2014/12/19/store-uuid-optimized-way/
     */
    public static function transposeUuid($uuid)
    {
        /*
         * orig UUID1: 13341cb5-c1f8-11e4-91e7-080027880ca6
         * transpose:  11e4-c1f8-13341cb5-91e7-080027880ca6
         * format:     11E4C1F813341CB591E7080027880CA6  <-- this is what can be ideally stored as binary in MySQL
         */
        $uuidOptimizedOrderForMySQL = substr($uuid, 14, 4) . substr($uuid, 9, 4) . substr($uuid, 0, 8) . substr(
                $uuid,
                19,
                17
            );
        $uuidFormattedForMySQL = strtoupper(str_replace('-', '', $uuidOptimizedOrderForMySQL));

        return $uuidFormattedForMySQL;
    }

...and the following related (example) entities:

/**
 * @Entity
 */
class Thing 
{
    /**
     * @Id
     * @var string UUID
     * @Column(type="uuid", length=16)
     * @GeneratedValue(strategy="CUSTOM")
     * @CustomIdGenerator(class="Fisdap\Doctrine\Extensions\IdGenerator\UuidGenerator")
     */
    protected $id;

   /**
     * @OneToOne(targetEntity="OtherThing", mappedBy="thing")
     */
    protected $otherThing;
}

/**
 * @Entity
 */
class OtherThing 
{
        /**
	 * @Id
	 * @Column(type="integer")
	 * @GeneratedValue
	 */
	protected $id;

       /**
	 * @OneToOne(targetEntity="Thing", inversedBy="otherThing")
	 */
	protected $thing;
}

In our case, since SchemaTool::gatherRelationJoinColumns() doesn't copy $fieldMapping['length'] to $columnOptions['length'] for non-string / custom data types, the resulting CREATE TABLE SQL for the OtherThing entity will have a column definition for its association with Thing as thing_id BINARY(0). Of course, MySQL/InnoDB will be unable to create the index for a column with zero length, and multiple exceptions are thrown.

I believe the fix here is to simply check whether $fieldMapping['length'] is set, regardless of the value of $fieldMapping['type']. For good measure, I did the same for $fieldMapping['scale'] and $fieldMapping['precision'].






[DDC-3720] Doctrine - Invalid column name 'sclr0' Created: 29/Apr/15  Updated: 29/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: DQL
Affects Version/s: None
Fix Version/s: 2.5.1
Security Level: All

Type: Task Priority: Major
Reporter: Belita Colares Assignee: Guilherme Blanco
Resolution: Unresolved Votes: 0
Labels: querybuilder


 Description   

My query doesn't work when i use ->setMaxResult with orderBy SUM.

My dataBase is MSSQL SERVER 2008 R2

$query = $entity->createQueryBuilder('t')
->select('SUM(t.price) AS test')
->setMaxResults(10)
>orderBy('test', 'ASC')>getQuery()->getResult();

when i use only
'->select('t.price AS test') ->setMaxResults(10) ->orderBy('test', 'ASC');' doesn't work too

Invalid column name 'sclr0'.
but when i comment this method setMaxResult() my query works fine.

Please help-me, I sorry my english.






[DDC-3718] Inifinite schema diff when using decimal with options unsigned Created: 29/Apr/15  Updated: 29/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Khang Minh Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: mysql, orm, schematool
Environment:

Php 5.6.7 (cli)
MariaDB 10.0.17
Symfony 2.6.1



 Description   

When using a mapping similar to:

        field_name:
            type: decimal
            scale: 2
            options:
                unsigned: true

I keep getting this when issuing app/console doctrine:schema:update --dump-sql (symfony console):

ALTER TABLE table_name CHANGE field_name field_name NUMERIC(10, 2) NOT NULL;

could be related to: http://www.doctrine-project.org/jira/browse/DC-752






[DDC-3717] [GH-1397] Add Expr::concat support for multiple arguments Created: 28/Apr/15  Updated: 28/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

DQL CONCAT function support variable number of arguments (2+) since version `2.4.0`.

The `Expr` class, on the other hand, is still limited to 2 arguments, and require multiple call to achive a similar result (see [this SO question](http://stackoverflow.com/questions/22169324/concat-three-or-more-fields-in-doctrine/29913780)). I've improved `Expr` implementation to support variable number of arguments in a backward compatible way.

Please, consider backporting to `2.4` branch if you plan to release other versions, since `2.5` introduce many features and may not be possible to easily upgrade. I may be wrong, though.






[DDC-3716] [GH-1396] [Documentation] Initializing embeddables doc Created: 27/Apr/15  Updated: 27/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:






[DDC-3697] WHERE conditions can get moved into JOIN conditions with JOINed Inheritance and non-association-JOINs Created: 17/Apr/15  Updated: 27/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: DQL
Affects Version/s: 2.4.7
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Malte Wunsch Assignee: Guilherme Blanco
Resolution: Unresolved Votes: 0
Labels: dql, orm


 Description   

With the following entities:

/**
 * @ORM\Entity()
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="discriminaor", type="integer")
 * @ORM\DiscriminatorMap({"1" = "GeneralEntity", "2" = "SpecializedEntity"})
 */
class GeneralEntity {
    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    protected $id;
}

/**
 * @ORM\Entity()
 */
class SpecializedEntity extends GeneralEntity {
}

you can create a DQL query (note we're JOINing freely here without traversing a defined association) like

SELECT g1.id
FROM GeneralEntity g1
JOIN GeneralEntity g2
WHERE g2.id = 1

This gets converted to the following SQL:

SELECT g0_.id AS id0
FROM GeneralEntity g0_
LEFT JOIN SpecializedEntity s1_ ON g0_.id = s1_.id
INNER JOIN GeneralEntity g2_
LEFT JOIN SpecializedEntity s3_ ON g2_.id = s3_.id AND (g2_.id = 1)

As you can see, the condition in the WHERE part (g2.id = 1) is no longer in a WHERE clause by it's own, but got moved to the LEFT JOIN of the table inheritance. In this simple special case it probably makes no difference, but in general it does and leads to wrong results.



 Comments   
Comment by Matthias Pigulla [ 27/Apr/15 ]

Here's my attempt at fixing it: https://github.com/doctrine/doctrine2/pull/1395.

Depending on what the WHERE condition looks like, instead of just selecting a small fraction of rows from the root table you may end up selecting all rows plus a mostly useless LEFT JOIN result.





[DDC-3715] [GH-1395] Fix for DDC-3697 Created: 26/Apr/15  Updated: 26/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

Also fix Lexer::match() so it does not accept T_WHERE when T_WITH is supposed to be matched. (DDC-3701)






[DDC-3714] [GH-1394] Fix result cache setting query caching Created: 24/Apr/15  Updated: 24/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

Hello!

This PR fixes the issue with result caching option when query caching is on.

Reproduce is pretty easy. Call same query twice: first time with `Query::useResultCache(true)`, second time with `Query::useResultCache(false)`. If query cache is on - `useResultCache()` setting will be cached along with query itself.

Use case is when you want to keep query cache always on but want sometimes to bypass result cache (e.g. you're sure that underlying data was updated).

P.S. Is it possible to backport fix to 2.4? I can provide another PR for it

Alex






[DDC-3713] [GH-1393] Composite key id used in nullable relations Created: 24/Apr/15  Updated: 24/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

This provides a fix, when you're using a composite primary key, and using part of the composite key as a join column, that will make sure you don't overwrite the composite id key.

Also the fix to Unit of Work needed to consider if part of a composite key was null, it should not try to map the entity.






[DDC-3712] [GH-1392] transactional() wrapper corrupts return values Created: 23/Apr/15  Updated: 23/Apr/15

Status: Awaiting Feedback
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.4, 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Minor
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 1
Labels: entitymanager, transactional


 Description   

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

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

Message:

The EntityManager::transactional() method has undocumented behavior, which unexpectedly rewrites all `false`-ish return values into `true` before passing them on:

    $result = $this->_em->transactional(function (){
        return array();
    }
    assert(is_array($result)); // Fails

I think there's a very strong case to be made that this is undesirable, *however* it's been in existence for a few years now (since DDC-1125) and it's very likely at least a few users have code that relies on the undocumented behavior.

This PR represents the most direct fix, but as a practical matter we may want to improve the documentation instead. If that is the decision, I'd be happy to create a separate PR for documentation changes.






[DDC-3711] Error on manyToMany with composite primary key Created: 23/Apr/15  Updated: 23/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Mapping Drivers
Affects Version/s: 2.5
Fix Version/s: 2.4.7
Security Level: All

Type: Bug Priority: Major
Reporter: Marc Pantel Assignee: Marco Pivetta
Resolution: Unresolved Votes: 0
Labels: None
Environment:

symfony 2.6



 Description   

Hi,
I hope that I report in the right place.
I have an issue when I try to create an manyToMany association with an entity with a composite primary key.
The problem is that only one of the two key are create on the association table.

I also have manyToOne association that works fine.

Here are the mapping

Commune.orm.yml

AppDemo\ZoneBundle\Entity\Commune:
    type: entity
    table: ref_commune
    id:
        codeInsee:
            type: string
            nullable: false
            length: 5
            fixed: true
            column: commune_code_insee
        codePostal:
            type: string
            nullable: false
            length: 5
            fixed: true
            column: commune_code_postal
    fields:
        nom:
            type: string
            nullable: false
            length: 100
            fixed: false
            column: commune_nom
    manyToMany:
        zones:
            targetEntity: Zone
            joinTable:
                name: lnk_zone_commune
                joinColumns:
                    commune_code_insee:
                        referencedColumnName: commune_code_insee
                    commune_code_postal:
                        referencedColumnName: commune_code_postal
                inverseJoinColumns:
                    zone_id:
                        referencedColumnName: zone_idx

Zone.orm.yml

AppDemo\ZoneBundle\Entity\Zone:
    type: entity
    repositoryClass: AppDemo\ZoneBundle\Repository\ZoneRepository
    table: ref_zone
    id:
        idx:
            type: integer
            nullable: false
            unsigned: false
            comment: ''
            id: true
            column: zone_idx
            generator:
                strategy: IDENTITY
    fields:
        libelle:
            type: string
            nullable: false
            length: 30
            options:
                default: ''
                comment: 'Libelle de la Zone'


 Comments   
Comment by Marco Pivetta [ 23/Apr/15 ]

What if you simply leave out the joinColumns mappings? Check what comes out of the metadata there, then compare it to your metadata (dump it)

Comment by Marc Pantel [ 23/Apr/15 ]

When I remove the JoinsColumns mapping, I get an error:

Column name `id` referenced for relation from AppBundle\Entity\Commune towards AppBundle\Entity\Zone does not exist.

How do I dump the metadata?





[DDC-3709] [GH-1391] [DDC-3693] Issue with notify change tracking policy Created: 22/Apr/15  Updated: 22/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:






[DDC-3700] orderBy stopped working after upgrading to 2.5v (Column not found error) Created: 19/Apr/15  Updated: 22/Apr/15

Status: Awaiting Feedback
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Khurshid Yalgashev Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: orderBy
Environment:

ubuntu 14.04


Attachments: JPEG File sl_notification.jpg    

 Description   

Hi,
I have this very simple method in my repository class which fetches a list as query builder object:

public function fetchListAsQueryBuilder(User $user, $receiverType, $limit, $offset)
{
    $queryBuilder = $this->getEntityManager()->createQueryBuilder();
    $query = $queryBuilder
        ->select(['no'])
        ->from('SLCoreBundle:Notification', 'no')
        ->where('no.receiver = :user')
        ->andWhere('no.receiverType = :receiverType')
        ->orderBy('no.createdAt', 'DESC')
        ->setParameters([
            'user' => $user,
            'receiverType' => $receiverType,
        ])
        ->setMaxResults($limit)
        ->setFirstResult($offset)
    ;

    return $query;
}

After upgrading to v2.5 it stopped working and is giving this error:

An exception occurred while executing 'SELECT DISTINCT id_6 FROM (SELECT s0_.receiver_type AS receiver_type_0, s0_.importance AS importance_1, s0_.seen AS seen_2, s0_.deleted AS deleted_3, s0_.created_at AS created_at_4, s0_.updated_at AS updated_at_5, s0_.id AS id_6, s0_.reason AS reason_7 FROM sl_notification s0_ WHERE s0_.receiver_id = ? AND s0_.receiver_type = ?) dctrn_result ORDER BY s0_.created_at DESC LIMIT 25 OFFSET 0' with params [2, 1]:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 's0_.created_at' in 'order clause'

My entity has been configured like this:

Mapped superclass AbstractMessage:

abstract class AbstractMessage
{
    use CreatedUpdatedAtTrait;

    // here go properties, setters and getter

Notification class:

class Notification extends AbstractMessage
{
    // here go properties, setters and getters

And CreateUpdatedAtTrait:

trait CreatedUpdatedAtTrait
{
    /**
     * @var \DateTime
     */
    private $createdAt;

    /**
     * @var \DateTime
     */
    private $updatedAt;

    // Here go setters and getters
}

Schema (AbstractMessage) :

<mapped-superclass name="SL\CoreBundle\Entity\AbstractMessage">

    ... 

    <field name="createdAt" column="created_at" type="datetime">
        <gedmo:timestampable on="create" />
    </field>

    <field name="updatedAt" column="updated_at" type="datetime">
        <gedmo:timestampable on="update" />
    </field>

</mapped-superclass>

I'dont understand what causes this error, my others entities work well with this trait, and also my other queries with orderBy method and mappedsuperclass classes work without any error. And also very interesting part is if I remove orderBy my method is working and I am able to get the createdAt value ($object->getCreatedAt()).

PS// Reference: http://stackoverflow.com/questions/29715104/error-with-orderby-column-not-found






[DDC-3708] Doctrine SQL filters and lazy loading causing EntityNotFoundException Created: 22/Apr/15  Updated: 22/Apr/15

Status: Reopened
Project: Doctrine 2 - ORM
Component/s: Lazy Loading, ORM
Affects Version/s: 2.4
Fix Version/s: None
Security Level: All

Type: Documentation Priority: Minor
Reporter: Pavle Predic Assignee: Marco Pivetta
Resolution: Unresolved Votes: 0
Labels: None


 Description   

When using a global SQL filter, lazy loading ManyToOne relations may lead to an EntityNotFoundException. You will always get a proxy object for the relation, but as soon as you try to access any property, doctrine will attempt to load the entity from DB, get zero results because the global filter has been applied (assuming that the filter affects the entity in question) and throw an EntityNotFoundException.

What is the recommended way of dealing with this issue globally? The use case is a CMS with a soft-delete feature. A global sql filter filters out entities with a deleted flag. One solution would be to write a custom ProxyFactory that doesn't throw the EntityNotFoundException or to write a custom ProxyGenerator that puts the initializer call in a try/catch block and returns null if an EntityNotFoundException is thrown.

This issue can be resolved by using "fetch EAGER" on ManyToOne relations, but this can lead to performance issues due to the large number of DB queries. How can this problem be solved while still using the lazy loading mechanism?



 Comments   
Comment by Marco Pivetta [ 22/Apr/15 ]

This sort of issue simply occurs when enabling SQL filters after any loading has already happened.

We can't fix this, you are supposed to call Doctrine\ORM\EntityManagerInterface#clear() right after enabling or disabling any filter.

Comment by Pavle Predic [ 22/Apr/15 ]

Filter is enabled from the start. I'm not sure if I managed to explain the issue properly, so let's use an example. Say we have the following entities:

Person (id, name, image_id, deleted)
Image (id, file_name, deleted)

Image is defined as a ManyToOne relation in Person.

Now let's say we have a global SQL filter that filters out all entities where deleted = 1.
Say we have the following data:
Person table:

1, "Jimi", 1, 0

Image table:

1, "jimi.jpg", 1

Now I load the person:

$person = $personRepository->find(1);

If I now access the related Image entity, I will get the instance of Proxy class:

$image = $person->getImage(); //no errors here, doctrine assumes that the relation exists, but doesn't attempt to load it from DB

When I try to get a specific Image attribute, I get an EntityNotFoundException:

$imagePath = $image->getFileName(); //throws an EntityNotFoundException

Obviously, I could use a try/catch block here, but I need a global solution. Most of the time, I'm accessing such relations in a twig template, which is not the best place to deal with exceptions.

Comment by Marco Pivetta [ 22/Apr/15 ]

Reopened: I obviously misunderstood the problem.

I don't think there is a doctrine-side solution to it.

Comment by Pavle Predic [ 22/Apr/15 ]

So definitely not possible to extend ProxyFactory or ProxyGenerator?

Or can this be made into a feature request where a specific config option would force the Proxy to return null instead of throwing an EntityNotFoundException?

Comment by Marco Pivetta [ 22/Apr/15 ]

Since it is an SQL-level filter, it would have to act at SQL level.

One possible solution is to always do joins on filtered associations, and then fetch either NULL or the identifier for those associations.





[DDC-3707] Getting Started contains a broken link Created: 21/Apr/15  Updated: 21/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Documentation
Affects Version/s: 2.x
Fix Version/s: None

Type: Documentation Priority: Minor
Reporter: Chris Smith Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: 404, documentation


 Description   

The reference to Zend DB is broken in the getting started documentation.



 Comments   
Comment by Chris Smith [ 21/Apr/15 ]

I think it should point to here: http://framework.zend.com/manual/1.12/en/zend.db.table.html





[DDC-3706] DQL parsing fail when using COUNT with "Simple Derived Identity" primary key Created: 21/Apr/15  Updated: 21/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: DQL, ORM
Affects Version/s: Git Master, 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Dmitry Korotovsky Assignee: Marco Pivetta
Resolution: Unresolved Votes: 0
Labels: bidirectional, count, onetoone, parser
Environment:

Mac osx Maverick
PHP 5.5.13
Nginx 1.6.0
Mysql 5.6.19


Attachments: File DDC3331Test.php    

 Description   

There is the regression https://github.com/doctrine/doctrine2/commit/097840dc935e1cfbc93fc673be077a8fe67e8e52

commit 097840dc935e1cfbc93fc673be077a8fe67e8e52
Author: Marco Pivetta <ocramius@gmail.com>
Date: Wed Aug 27 01:56:11 2014 +0200

Allowing expression in `COUNT()` DQL aggregation functions

:040000 040000 5d5f12583a38f54e5966b1cb65dfe487d932a728 982b2c8642e311730b48c6e5d6e6740c97e3bd5c M lib

On Doctrine 2.5.0 FOSElasticaBundle doesn't work completely

$ php app/console fos:elastica:populate --env=test
Resetting users
Refreshing users

[Doctrine\ORM\Query\QueryException]
[Semantical Error] line 0, col 13 near 'a) FROM F\Q\C\N\Entity\UserProfile': Error: Invalid PathExpression. Must be a StateFieldPathExpression.

[Doctrine\ORM\Query\QueryException]
SELECT COUNT(a) FROM F\Q\C\N\Entity\UserProfile a






[DDC-3705] Order by With Equals is not supported Created: 20/Apr/15  Updated: 20/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: DQL
Affects Version/s: 2.4.7
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Alexey Kosov Assignee: Guilherme Blanco
Resolution: Unresolved Votes: 0
Labels: dql


 Description   

Related to this issue: http://www.doctrine-project.org/jira/browse/DDC-2204
Solution proposed by Benjamin Eberlei doesn't work so the issue it still unresolved.

SELECT
e.status = 1 AS HIDDEN orderField
FROM
Entity e
ORDER BY
orderField DESC

Doctrine\ORM\Query\QueryException
\vendor\doctrine\orm\lib\Doctrine\ORM\Query\QueryException.php:52
[Syntax Error] line 0, col 47: Error: Expected Doctrine\ORM\Query\Lexer::T_FROM, got '='






[DDC-3704] [GH-1390] Document the ChainCache class Created: 20/Apr/15  Updated: 20/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

I was thisclose to writing a ChainCache class myself, and only avoided it by actually looking in the source. There's no mention of ChainCache on Google, probably because there's no docs for it. ChainCache is a bit different from other drivers in that it's something implementers will want to use in their own code in place of an ArrayCache or static array. However, I also added a link to the cache drivers given there's quite a few that aren't mentioned in the docs.






[DDC-3703] [GH-1389] Fix Lexer::match() so it does not accept T_WHERE when T_WITH is supposed to be matched Created: 19/Apr/15  Updated: 19/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

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



 Comments   
Comment by Matthias Pigulla [ 19/Apr/15 ]

This is the PR for DDC-3701. Please close or mark as duplicate of DDC-3701, whatever your workflow is.





[DDC-3702] [GH-1388] Fix Lexer::match() so it does not accept T_WHERE when T_WITH is supposed to be matched Created: 19/Apr/15  Updated: 19/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

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



 Comments   
Comment by Doctrine Bot [ 19/Apr/15 ]

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

Comment by Matthias Pigulla [ 19/Apr/15 ]

Please disregard / close.





[DDC-3701] Questions regarding Parser::match and "identifier" EBNF Created: 19/Apr/15  Updated: 19/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: DQL, ORM
Affects Version/s: 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Minor
Reporter: Matthias Pigulla Assignee: Guilherme Blanco
Resolution: Unresolved Votes: 0
Labels: None


 Description   

I am currently investigating a problem where I am suspecting the DQL parser to wrongly transform a DQL statement to SQL. While I haven't yet found the exact reason (will open a new case for it), I have come across the following in the Parser::match() method:

   if ($lookaheadType !== $token && $token !== Lexer::T_IDENTIFIER && $lookaheadType <= Lexer::T_IDENTIFIER) {
      $this->syntaxError($this->lexer->getLiteral($token));
   }

The if-condition was changed a while ago in order to allow DQL terms like WHERE to appear as identifiers.

I think that the condition is wrong as it will only fail (create the syntax error) when the actual token does not match the expected type, we're not expecting an "identifier" and the next token is something special like punctuation that could not serve as an identifier.

So, for example when we're match()ing a T_WITH, a T_WHERE will be accepted as well. A correct check would probably not solve my actual problem, but it would probably have been spotted much earlier due to syntax errors issued.

IMO this should actually read

if ($lookaheadType !== $token && ($token !== Lexer::T_IDENTIFIER || $lookaheadType <= Lexer::T_IDENTIFIER)) { ... syntax error ... }

That is, fail if the token does not match the expectation; and when the expectation is T_IDENTIFIER, also accept every terminal string that can also be considered an "identifier".

With this change, the tests almost pass. The only problem is when a FROM clause expects an "identifier" and now a fully qualified class name starting with a backslash is no longer accepted.

Unfortunately, I also did not manage to find an exact definition of "identifier" somewhere in the EBNF. Lexer::getType() considers everything that starts with a character or underscore an identifier, but that does not match FQCNs.

As there seems to be no special token for backslashes, I tried allowing the backslash as a starting character for identifiers as well (in the Lexer), and it seems to work (all non-skipped tests pass).

What do you think about it? Is that something we should fix and does my change make sense?






[DDC-3696] flushing traversable objects Created: 17/Apr/15  Updated: 18/Apr/15

Status: Awaiting Feedback
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.5, 2.5.1
Fix Version/s: None
Security Level: All

Type: New Feature Priority: Major
Reporter: mw Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: orm, unitofwork


 Description   

Hi,

https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/UnitOfWork.php#L331

it would be easier if you could the method "flush" pass a traversable object. I've implement this behavior in my decorated entity manager. In my opinion this should be an official supported behavior.

The new code should be inside of Orm\UnitOfWork::commit($entity = null) and looks like the following code:

// Compute changes done since last commit.
if( $entity instanceof \Traversable ) {
	$entity = iterator_to_array( $entity );
}

By the way, the foreach part can be simplified to one line. This can be made possible by array_walk.
You can use:

} elseif (is_array($entity)) {
	array_walk($entity, array($this, 'computeSingleEntityChangeSet'));
}

Now, the new code in one piece:

// Compute changes done since last commit.
if( $entity instanceof \Traversable ) {
	$entity = iterator_to_array( $entity );
}

if ($entity === null) {
	$this->computeChangeSets();
} elseif (is_object($entity)) {
	$this->computeSingleEntityChangeSet($entity);
} elseif (is_array($entity)) {
	array_walk($entity, array($this, 'computeSingleEntityChangeSet'));
}

Thanks in advance.



 Comments   
Comment by Marco Pivetta [ 17/Apr/15 ]

Two things:

1) we are more inclined to remove the parameter from flush(), as it was exploited for purposes it wasn't designed for.
2) what happens if you persist an entity that is a traversable?

Comment by mw [ 17/Apr/15 ]

1.Is that really planned? I guess this is a helpful feature and makes not a difference if you flush a small collection of entities before you flush the remaining entities without the parameter.

2. The object will be treated as entity, because it's an object. This will throw an "Doctrine\ORM\Mapping\MappingException" exception with following message:

Class "SplObjectStorage" is not a valid entity or mapped super class.
Exception-Class: Doctrine\ORM\Mapping\MappingException 
Exception-Code: 0 
Exception-File: Composer/doctrine/orm/lib/Doctrine/ORM/Mapping/MappingException.php 
Exception-Line: 346

This simple senseless code shows you what you can do to test this behavior.

$em = Doctrine_Factory::getEntityManager();
$em->persist($entity);
$x = new SplObjectStorage();
$x->attach($entity);
$em->flush($x);
Comment by Marco Pivetta [ 17/Apr/15 ]

You can implement the Traversable interface (as iterator or iteratoraggregate) on any entity.

As for "planned", it obviously won't happen in 2.x.

We are mainly interested in finding better ways to speed up flush() operations rather than delegating transactional boundaries knowledge to the user.

Anyway, so far, flush($entities) has been more of a source of bugs rather than an actual useful API.

Comment by mw [ 18/Apr/15 ]

The Traversable interface serves to detect whether a class is traversable using foreach. The flush parameter surrenders this parameter one-to-one to $this->unitOfWork->commit($entity).
What I want to do is to hand over an traversable object to the method EntityManager::flush with a collection of entities instead of an single entity object. It's also possible to pass a collection of entities as array. But it's not possible to pass a collection of entities as an object, because when passing an object UnitOfWork::commit assumes that it's an entity. To implement the Traversable interface on any entity will not help and is not the same intention. Because an Traversable object it means, that is a collection of entities like an array.

In my opinion there are not objections that speak against it to support traversable object (SplObjectStorage, ArrayIterator, ArrayObject).

There are two ways to do that.

The first option would be:

// Compute changes done since last commit.
if( $entity instanceof \Traversable ) {
	$entity = iterator_to_array( $entity );
}

if ($entity === null) {
	$this->computeChangeSets();
} elseif (is_object($entity)) {
	$this->computeSingleEntityChangeSet($entity);
} elseif (is_array($entity)) {
	array_walk($entity, array($this, 'computeSingleEntityChangeSet'));
}

The second option would be:

// Compute changes done since last commit.
if ($entity === null) {
	$this->computeChangeSets();
} elseif (is_array($entity) || $entity instanceof \Traversable) {
	foreach ($entity as $object) {
		$this->computeSingleEntityChangeSet($object);
	}
} elseif (is_object($entity)) {
	$this->computeSingleEntityChangeSet($entity);
}

By the way: the SplObjectStorage object has the benefit that every entity is present only once.





[DDC-3699] [GH-1387] Fix skipping properties if they are listed after a not loaded relation. Created: 17/Apr/15  Updated: 18/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

This issue fixes an issue that occurs when merging entites, when the entity that is being merged has some other properties after a association type field.

Fixes the following scenario :
Your entity extends a parent entity and when it is merged by the entity manager first its fields are computed, this is done correctly bby `ReflectionPropertiesGetter::getProperties()`, but in the `mergeEntityStateIntoManagedCopy` method the iteration is stopped when it gets to a field that is a relationship and it is Proxy and was not loaded yet.
The order in which the fields are computed is : current class properties and then the parent properties, so if the current class has a lazy loaded relationship then the properties of the parent are not merged.

So the fix doesn't stop the iteration it just skips the current property that is not loaded yet and goes to the next property.



 Comments   
Comment by Doctrine Bot [ 18/Apr/15 ]

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





[DDC-3691] Filtering by 'date' column does not return enough values on SQLite Created: 14/Apr/15  Updated: 17/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: Git Master
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: XitasoChris Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Windows 8.1 x64
PHP 5.6.2
date.timezone => Europe/Berlin


Attachments: Zip Archive sandbox.zip    

 Description   

When using a column of type 'date' in a where clause, filtering fails and does not return entries which clearly should match.

I have implemented a small proof of concept on the Doctrine sandbox. You can find it by checking out my branch at https://github.com/XitasoChris/doctrine2/tree/date_filter_bug and then run the tools/sandbox/index.php . Alternatively, I have zipped the sandbox folder and attached it to this bug report.

I don't know whether this affects other database systems as well. I only tested it on SQLite.



 Comments   
Comment by Marco Pivetta [ 14/Apr/15 ]

Linking the diff: https://github.com/doctrine/doctrine2/compare/master...XitasoChris:date_filter_bug

Should be a test case, XitasoChris - can you convert it?

Comment by XitasoChris [ 14/Apr/15 ]

@Marco: I will try, though I have never done that on the doctrine project before.

Comment by XitasoChris [ 14/Apr/15 ]

Test case created: https://github.com/doctrine/doctrine2/pull/1383

Comment by XitasoChris [ 17/Apr/15 ]

After some more debugging: The problem is that the type of the parameter is inferred as "datetime", leading Doctrine to format the value as "2015-03-01 00:00:00". However, SQLite needs the value formatted as "2015-03-01" to find a match.

A workaround is to tell Doctrine to format the parameter as a date [$queryBuilder->setParameter("date", $date, "date")] and then the test case works fine.

My question now is: is this behavior expected? If so, then the bug report is probably invalid.





[DDC-3552] Code generation throws exceptions when embeddables are used Created: 30/Jan/15  Updated: 17/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Vladislav Veselinov Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

I've created a gist showing the code you can use to reproduce the issue
https://gist.github.com/v3labs/d02244c99a87444be709

I've also included the composer.json file.

When I run php app/console doctrine:generate:entities AppBundle -v, I get the following exception:

[Symfony\Component\Debug\Exception\ContextErrorException]
Notice: Trying to get property of non-object

Exception trace:
() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:3251
Symfony\Component\Debug\ErrorHandler->handleError() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:3251
Doctrine\ORM\Mapping\ClassMetadataInfo->inlineEmbeddable() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:201
Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:332
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78
Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:225
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:115
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/doctrine-bundle/Mapping/DisconnectedMetadataFactory.php:201
Doctrine\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory->getAllMetadata() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/doctrine-bundle/Mapping/DisconnectedMetadataFactory.php:164
Doctrine\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory->getMetadataForNamespace() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/doctrine-bundle/Mapping/DisconnectedMetadataFactory.php:54
Doctrine\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory->getBundleMetadata() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/doctrine-bundle/Command/GenerateEntitiesDoctrineCommand.php:96
Doctrine\Bundle\DoctrineBundle\Command\GenerateEntitiesDoctrineCommand->execute() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:253
Symfony\Component\Console\Command\Command->run() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:882
Symfony\Component\Console\Application->doRunCommand() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:195
Symfony\Component\Console\Application->doRun() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
Symfony\Component\Console\Application->run() at /Users/vladislav/Sites/doctrine2.5_tests/app/console:27

If I add columnPreffix to the @Embed annotation the exception is different:

[Symfony\Component\Debug\Exception\ContextErrorException]
Catchable Fatal Error: Argument 1 passed to Doctrine\ORM\Mapping\ReflectionEmbeddedProperty::__construct() must be an instance of ReflectionP
roperty, null given, called in /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php on
line 952 and defined

Exception trace:
() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php:61
Symfony\Component\Debug\ErrorHandler->handleError() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ReflectionEmbeddedProperty.php:61
Doctrine\ORM\Mapping\ReflectionEmbeddedProperty->__construct() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:952
Doctrine\ORM\Mapping\ClassMetadataInfo->wakeupReflection() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:721
Doctrine\ORM\Mapping\ClassMetadataFactory->wakeupReflection() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:343
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:78
Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:225
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:115
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/doctrine-bundle/Mapping/DisconnectedMetadataFactory.php:201
Doctrine\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory->getAllMetadata() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/doctrine-bundle/Mapping/DisconnectedMetadataFactory.php:164
Doctrine\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory->getMetadataForNamespace() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/doctrine-bundle/Mapping/DisconnectedMetadataFactory.php:54
Doctrine\Bundle\DoctrineBundle\Mapping\DisconnectedMetadataFactory->getBundleMetadata() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/doctrine/doctrine-bundle/Command/GenerateEntitiesDoctrineCommand.php:96
Doctrine\Bundle\DoctrineBundle\Command\GenerateEntitiesDoctrineCommand->execute() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/symfony/symfony/src/Symfony/Component/Console/Command/Command.php:253
Symfony\Component\Console\Command\Command->run() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:882
Symfony\Component\Console\Application->doRunCommand() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:195
Symfony\Component\Console\Application->doRun() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /Users/vladislav/Sites/doctrine2.5_tests/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:126
Symfony\Component\Console\Application->run() at /Users/vladislav/Sites/doctrine2.5_tests/app/console:27

doctrine:generate:entities [--path="..."] [--no-backup] name

I don't think it's a Symfony specific issue. I tried using the built-in CLI tool and got the same results.



 Comments   
Comment by Marco Pivetta [ 30/Jan/15 ]

Yeah, this can't really work with code-gen, because embeddables require reflection to be initialized in order to operate, whereas the codegen cli-tools operate with a DisconnectedMetadataFactory, which skips reflection on purpose (it assumes that the class does not exist, therefore it does not start up reflection).

I think it's a can't fix for now.

Comment by Vladislav Veselinov [ 30/Jan/15 ]

Sorry for the formatting. I had never used jira before.

Comment by Marco Pivetta [ 30/Jan/15 ]

Vladislav Veselinov fixed the formatting, no big deal

Comment by Vladislav Veselinov [ 30/Jan/15 ]

Btw:

Changing line 947 in ClassMetadataInfo to:

if (isset($mapping['declaredField']) && $parentReflFields[$mapping['declaredField']]) {

seems to bypass the problem and the generation runs fine, but I don't know if it breaks something else. Doesn't seem like it but ... I'm not sure

Comment by Vladislav Veselinov [ 30/Jan/15 ]

Just figured out with it won't work in all cases. I'll keep digging. Thanks for the feedback!

Comment by Konstantinos Christofilos [ 17/Apr/15 ]

Hi,
I was encountered the same issue with embeddables, but it seems to work fine if you define production environment in command:

php app/console doctrine:generate:entities AppBundle --env=prod




[DDC-2795] the queryBuider Expr\Join class has a ON type but unsupported by the parser Created: 14/Nov/13  Updated: 16/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Documentation, DQL
Affects Version/s: 2.4.1
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Christophe Coevoet Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 2
Labels: documentation, dql, querybuilder,


 Description   

The Doctrine\ORM\Query\Expr\Join class has 2 cosntants for the condition types: WITH and ON.

None of them are documented. The only place where WITH appear is the EBNF, which is outdated in the doc as it does not show arbitrary joins (added in 2.3) but only association joins.

and when looking at the EBNF in the code, I find 2 different ones (none of them matching the one given in the doc):

  • in Doctrine\ORM\query\Parser::Join:
Join ::= ["LEFT" ["OUTER"] | "INNER"] "JOIN"
         (JoinAssociationDeclaration | RangeVariableDeclaration)
         ["WITH" ConditionalExpression]

This is matching the implementation and ON is not supported.

  • in Doctrine\ORM\Query\AST\Join:
Join ::= ["LEFT" ["OUTER"] | "INNER"] "JOIN" JoinAssociationPathExpression
         ["AS"] AliasIdentificationVariable [("ON" | "WITH") ConditionalExpression]

This one is missing 2 features also missing in the doc (INDEX BY for associations, and arbitrary joins) and adds the support of ON which is not implemented.

What is the reason to have this ON constant in the query builder ? It is confusing to get a DQL parse exception when using it if it is there.

On a side note, what is the canonical source for the EBNF ? There is 2 different locations in the code (the phpdoc of parser methods and the phpdoc of AST nodes created by the parser), plus the doc. Shouldn't we try to limit the duplication and have a way to check the consistency of the doc ?



 Comments   
Comment by Matthias Pigulla [ 16/Apr/15 ]

Seems http://www.doctrine-project.org/jira/browse/DDC-135 deals with the initial feature addition of WITH. ON was not implemented at that time at least.





[DDC-3693] Notify change tracking policy breaks in the face of individual entity flushes Created: 15/Apr/15  Updated: 15/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.2.2, 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Michael Nielsen Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 2
Labels: None


 Description   

The notify change tracking policy breaks, if other entities are individually flushed between change and flush on a given notify-based entity.

The culprit seems to be that UnitOfWork.commit() resets its scheduledForSynchronization and entityChangeSets arrays (name(s) has changed since 2.2.2) - even when the commit is for a single entity, and the arrays hold other scheduled entities/changes.

An example:

use \net\jay\test\A;

$em = \Doctrine2::getEntityManager();

# persist and flush two instances of A
$a1 = new A(1, 'x');
$a2 = new A(2, 'y');
$em->persist($a1);
$em->persist($a2);
$em->flush();

# change both, but flush $a2 first, then do a general flush
$a1->setName('xx');
$a2->setName('yy');
$em->flush($a2);
$em->flush();

# $a1 entity should be changed, but isn't
$em->clear();
$a1 = $em->getRepository('net\jay\test\A')->find(1);
echo $a1->getName(); # = 'x' (should be 'xx')
namespace net\jay\test;

/**
 * @Entity
 * @ChangeTrackingPolicy("NOTIFY")
 */
class A implements \Doctrine\Common\NotifyPropertyChanged
{
	/** @Id @Column(type="integer") */
	private $id;
	
	/** @Column(length=100) */
	private $name;
	
	private $_changeListeners;
	
	public function __construct($id, $name)
	{
		$this->id = $id;
		$this->name = $name;
	}
	
	public function addPropertyChangedListener(\Doctrine\Common\PropertyChangedListener $listener)
	{
		$this->_changeListeners[] = $listener;
	}
	
	private function _onPropertyChanged($propName, $oldValue, $newValue)
	{
		if ($this->_changeListeners)
		{
			foreach ($this->_changeListeners as $listener)
			{
				$listener->propertyChanged($this, $propName, $oldValue, $newValue);
			}
		}
	}
	
	public function getID()
	{
		return $this->id;
	}
	
	public function getName()
	{
		return $this->name;
	}
	
	public function setName($name)
	{
		$this->_onPropertyChanged('name', $this->name, $name);
		$this->name = $name;
	}
}





[DDC-3690] PersistentCollection uses private property Created: 14/Apr/15  Updated: 15/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Lazy Loading, ORM
Affects Version/s: 2.5
Fix Version/s: 2.5.1
Security Level: All

Type: Bug Priority: Blocker
Reporter: Roel Assignee: Marco Pivetta
Resolution: Unresolved Votes: 0
Labels: collection, persistent-collection, release


 Description   

1. PersistentCollection in Doctrine 2.5 makes uses of the $initialized property defined in the AbstractLazyCollection of doctrine\collection (https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/PersistentCollection.php#L113)
2. Doctrine 2.5 depends on version ~1.2 of doctrine\collection that marks the $initialized property as private https://github.com/doctrine/collections/blob/v1.2/lib/Doctrine/Common/Collections/AbstractLazyCollection.php
3. Hence writing to the initialized variable fails. And thus code related to initialization fails.

A fix is already applied to doctrine\orm https://github.com/doctrine/collections/commit/e2eef4629349fd847c8e080b8f729ab33e81e10f but is not tagged. Possible fix would be to release a new version of doctrine\collection as 1.2.1.



 Comments   
Comment by Roel [ 14/Apr/15 ]

Due to this several tests fail in our code-base.

Comment by Marco Pivetta [ 14/Apr/15 ]

This is a bug caused by the fact that ORM 2.5 should depend on Collections 1.3.0 - I'll look into it ASAP.

Comment by Marco Pivetta [ 15/Apr/15 ]

Collections 1.3.0 was released, but I'll keep this open until ORM 2.5.1 is out.





[DDC-3687] Entities part of a hierarchy seem not to inherit SLC configuration from 'root' Entity Created: 13/Apr/15  Updated: 15/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Second Level Cache
Affects Version/s: 2.5
Fix Version/s: None
Security Level: All

Type: Documentation Priority: Minor
Reporter: Menno Holtkamp Assignee: Fabio B. Silva
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Reference
relates to DDC-3689 [GH-1382] Patch second level cache as... Resolved

 Description   

When using the Second Level Cache on associations, the documentation states that "the target entity must also be marked as cacheable"

It seems that when this targetEntity is an (possibly abstract) 'root' Entity of an Entity hierarchy, all Entities of that hierarchy need to be marked as cacheable. I would expect that all Entities that are part of the Entity hierarchy, also inherit this cache configuration metadata of the root Entity...

Is this intended behavior?

For example, this does NOT work:

Entity
 - cacheable X-to-many association, targetEntity: RootEntity

RootEntity, SINGLE_TABLE (marked as cacheable)
 - SubEntity1
 - SubEntityN

The generated error:

Array
(
    [type] => 1
    [message] => Call to a member function resolveAssociationEntries() on a non-object
    [file] => /srv/www/code/vendor/doctrine/orm/lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php
    [line] => 92
)

For example, this does DOES work

Entity
 - cacheable X-to-many association, targetEntity: RootEntity

RootEntity, SINGLE_TABLE 
 - SubEntity1 (marked as cacheable)
 - SubEntityN (marked as cacheable)


 Comments   
Comment by Fabio B. Silva [ 13/Apr/15 ]

Hi Menno Holtkamp All subclasses should already Inherit the cache configuration .

Can please attach your entities/mapping ?

Comment by Menno Holtkamp [ 13/Apr/15 ]

Mm, you are right, the cache configuration seems to be inherited. General idea of my Mapping is at the end of this comment.

The error occurs after the cache has been filled (2nd request). The following CollectionCacheEntry is used to lookup the EntityEntries:

identifiers => Array ( [0] => Doctrine\ORM\Cache\EntityCacheKey Object ( [identifier] => Array ( [id] => 357 )
entityClass => Project\Domain\Entity\Cms\Page\SectionAbstract
hash => project.domain.entity.cms.page.sectionabstract_357

This results in a $entityEntries collection with one entry, (which is empty!) as retrieved from cache at:
https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Cache/DefaultCollectionHydrator.php#L84

array(1) {
  [0] =>
  NULL
}

Having a look at the actual content of the SLC cache shows that the entry exists, so the lookup goes wrong. It seems 'DefaultRegion::getMultiple()' contains a bug:

https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Cache/Region/DefaultRegion.php#L122

$returnableItems[$index] = $items[$key];

Should be

$returnableItems[$index] = $items[$index];

Since the $items array uses the same keys as the $keysToRetrieve array, filled at https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Cache/Region/DefaultRegion.php#L106

My mapping (pseudo-code)

/**
 * @Entity
 * @Cache
 */
class Page
{
	/**
	 * @OneToMany
	 * @Cache
	 */
	private $translations;
}

/**
 * @Entity
 * @Cache
 */
class Translation
{
	/**
	 * @ManyToOne
	 */
	private $page;
	
	/**
	 * @OneToMany
	 * @Cache
	 */
	private $sections;
}

/**
 * @Entity
 * @Cache
 */
abstract class SectionAbstract
{
	/**
	 * @ManyToOne
	 */
	private $pageTranslation;
}

/**
 * @Entity
 */
class SectionFaq extends SectionAbstract
{

	/**
	 * @var string
	 */
	private $answer;
	
	/**
	 * @var string
	 */
	private $question;
}

/**
 * @Entity
 */
class SectionText extends SectionAbstract
{
	/**
	 * @var string
	 */
	private $content;
}
Comment by Fabio B. Silva [ 13/Apr/15 ]

Yes, it looks like a bug on DefaultRegion::getMultiple()
Can you try to write a failing test case or/and maybe send a PR ?

Comment by Menno Holtkamp [ 13/Apr/15 ]

Mm, will try to find some time this week. Not very experienced in writing test cases though...

Comment by Fabio B. Silva [ 13/Apr/15 ]

Cool,
Take a look at : SecondLevelCacheTest and let me know if you need help..

Comment by Menno Holtkamp [ 13/Apr/15 ]

Ok, challenge accepted, got a test case running in this branch, I used:

php ./vendor/bin/phpunit -v --exclude-group performance,non-cacheable,locking_functional --filter DefaultRegionTest

It seems the way DefaultRegion::getMultiple() works is overcomplicated? Maybe just return the $items array as an end-result?

Comment by Fabio B. Silva [ 13/Apr/15 ]

If you want to refactory it some how, that will be great..
DefaultRegion::getMultiple tries to check if all keys are found in the cache, and then maps it back to the original key
If any of then are missing it will return null which will trigger a new database query to reload the entries and repopulate the cache.

Overall you branch seems good, Can you send a PR please ?

Comment by Menno Holtkamp [ 14/Apr/15 ]

Ok, I gave it a shot at https://github.com/doctrine/doctrine2/pull/1382, AFAIK the index of the resulting array can just be numeric, right?

Comment by Doctrine Bot [ 14/Apr/15 ]

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

Comment by Doctrine Bot [ 14/Apr/15 ]

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

Comment by Doctrine Bot [ 14/Apr/15 ]

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

Comment by Doctrine Bot [ 15/Apr/15 ]

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

Comment by Doctrine Bot [ 15/Apr/15 ]

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





[DDC-3692] [GH-1383] DDC-3691 add test case Created: 14/Apr/15  Updated: 14/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

Test case for DDC-3691






[DDC-2381] Pagination query can be simplified when simple joins are applied Created: 31/Mar/13  Updated: 14/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.3, 2.4
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Minor
Reporter: Sergey Gerdel Assignee: Marco Pivetta
Resolution: Unresolved Votes: 3
Labels: paginator

Attachments: HTML File EXPLAIN.htmL     HTML File EXPLAIN1.html     HTML File EXPLAIN2.html     HTML File EXPLAIN3.htm     HTML File EXPLAIN4.htm    

 Description   

Hi.
In mysql db table i have > 200,000 items.
I use native doctrine pagination for paging the items list.
But generated query that gets ids for items list in paging works more then 150 sec on my workstation

SELECT DISTINCT id0 FROM (SELECT m0_.id AS id0, m0_.title AS title1, m0_.text AS text2, m0_.price AS price3, m0_.originalPrice AS originalPrice4, m0_.condition_type AS condition_type5, m0_.image_1 AS image_16, m0_.image_2 AS image_27, m0_.image_3 AS image_38, m0_.image_4 AS image_49, m0_.image_5 AS image_510, m0_.video AS video11, m0_.contact_email AS contact_email12, m0_.contact_name AS contact_name13, m0_.contact_phone AS contact_phone14, m0_.contact_type AS contact_type15, m0_.published AS published16, m0_.type AS type17, m0_.status AS status18, m0_.highlight AS highlight19, m0_.urgent AS urgent20, m0_.topads AS topads21, m0_.period AS period22, m0_.hits AS hits23, m0_.ip AS ip24, m0_.created_at AS created_at25, m0_.updated_at AS updated_at26 FROM milla_message m0_ INNER JOIN milla_currency m1_ ON m0_.currency_id = m1_.id INNER JOIN milla_category m2_ ON m0_.category_id = m2_.id INNER JOIN milla_region m3_ ON m0_.region_id = m3_.id INNER JOIN milla_city m4_ ON m0_.city_id = m4_.id WHERE m0_.status = 1 ORDER BY m0_.published DESC) dctrn_result LIMIT 20 OFFSET 0

source code
https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php#L141

why SELECT DISTINCT %s FROM (%s) dctrn_result ???
why not SELECT DISTINCT m0_.id AS id0 FROM milla_message m0_ WHERE m0_.status = 1 ORDER BY m0_.published DESC LIMIT 20 OFFSET 0



 Comments   
Comment by Marco Pivetta [ 31/Mar/13 ]

Not a blocker

Comment by Marco Pivetta [ 31/Mar/13 ]

What's the result of `EXPLAIN` on a query without the subquery?

Comment by Sergey Gerdel [ 31/Mar/13 ]

explain without the subquery

Comment by Marco Pivetta [ 31/Mar/13 ]

Sergey Gerdel that's not the same query.

Comment by Marco Pivetta [ 31/Mar/13 ]

Sergey Gerdel this is still using

Using index; Using temporary; Using filesort

Check your indexes

Comment by Sergey Gerdel [ 31/Mar/13 ]

Not in the index problem

SELECT DISTINCT id0 FROM (SELECT m0_.id AS id0, m0_.title AS title1, m0_.text AS text2, m0_.price AS price3, m0_.originalPrice AS originalPrice4, m0_.condition_type AS condition_type5, m0_.image_1 AS image_16, m0_.image_2 AS image_27, m0_.image_3 AS image_38, m0_.image_4 AS image_49, m0_.image_5 AS image_510, m0_.video AS video11, m0_.contact_email AS contact_email12, m0_.contact_name AS contact_name13, m0_.contact_phone AS contact_phone14, m0_.contact_type AS contact_type15, m0_.published AS published16, m0_.type AS type17, m0_.status AS status18, m0_.highlight AS highlight19, m0_.urgent AS urgent20, m0_.topads AS topads21, m0_.period AS period22, m0_.hits AS hits23, m0_.ip AS ip24, m0_.created_at AS created_at25, m0_.updated_at AS updated_at26 FROM milla_message m0_ WHERE m0_.status = 1 ORDER BY m0_.published DESC) dctrn_result LIMIT 20 OFFSET 0

Time: 104.614s explain 3

SELECT DISTINCT m0_.id AS id0 FROM milla_message m0_ WHERE m0_.status = 1 ORDER BY m0_.published DESC LIMIT 20 OFFSET 0;

Time: 0.001s explain 4

Comment by Marco Pivetta [ 01/Apr/13 ]

Sergey Gerdel the ORM cannot simplify a complex query that way. There may be a conditional on one of the joined results, or generally usage of one of the joined results.

Things that could be optimized here are:

  • Removal of the `ORDER BY` clause when grouping (check ORM master, I think somebody already did that)
  • Trying to simplify the query by doing some serious hacking on the AST.

The problem I see here is that the chance to spawn random bugs because of the optimization is very high, and you'd have to rewrite `walkSelectStatement`

Comment by Marco Pivetta [ 01/Apr/13 ]

Marking as improvement

Comment by Sergey Gerdel [ 07/Apr/13 ]

Minor?
i have 100 sec for this query.
200k items are selected for temporary table. wtf?

OK. Programmers may be mistaken in parser
expect ORDER BY m0_.published DESC LIMIT 20 OFFSET 0) dctrn_result
Time: 0.001s

reality ORDER BY m0_.published DESC) dctrn_result LIMIT 20 OFFSET 0

Comment by Marco Pivetta [ 07/Apr/13 ]

Sergey Gerdel this problem does not introduce security issues and can be worked around by you while using your own pagination logic. It does not stop you from doing anything, that's why it's minor.

Comment by Sergey Gerdel [ 08/Apr/13 ]

ok)
i have already created my own paginator.
at last
please see how to fix this problem
https://github.com/Sergic/doctrine2/commit/2733c815387273d3bd199a68acb717e0cbc8ccfe

Comment by Tom Pryor [ 11/Oct/13 ]

I've also run into this problem which makes Doctrine's Paginator useless for large datasets. The actual query takes 0.002ms but the SELECT DISTINCT query doctrine executes takes over 30s because MySQL creates a temporary table with 200k+ records.

You don't need to remove the joined tables from the paginator query (I have conditions on the joined tables anyway), this has a negligible impact performance, but rather it is caused by SELECT DISTINCT and ORDER BY which no index configuration can solve. Rather, perhaps a flag could be added to the paginator to indicate my query does not fetch join any has many collections (i.e each row returned will be unique) negating the need for the SELECT DISTINCT. The pagination would only then need to perform the original query with LIMIT and OFFSET applied along with a separate COUNT query on the primary key, both of which are very fast as they'd use the indexes setup for the the original query.

Comment by Christophe Coevoet [ 11/Oct/13 ]

This flag already exists for the select query. See the second argument of the constructor.

For the count query, you should call $paginator->setUseOutputWalkers(false) to make it use a DQL AST walker instead of the SQL Output walker (the AST walker does not support counting on queries using HAVING which is why it is not selected by default)

Comment by Robert (Jamie) Munro [ 29/Nov/13 ]

I think this is more important than "minor", as I've experienced this when upgrading from 2.2. My site became unusably slow.

I can't easily work around it because I am using Symfony bundles that use this, I am not using this directly. None of the workarounds mentioned so far seem to have helped.

Comment by Matthias Pigulla [ 14/Apr/15 ]

http://www.doctrine-project.org/jira/browse/DDC-3646 seems to be related or identical.





[DDC-3646] Do not select unused columns in inner queries of Paginator Created: 31/Mar/15  Updated: 14/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Tools
Affects Version/s: 2.4.7
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Minor
Reporter: Malte Wunsch Assignee: Steve Müller
Resolution: Unresolved Votes: 1
Labels: paginator
Environment:

In my case MySQL 5.1, other versions or DBMS may optimise that by themselves



 Description   

When a {{Paginator count()}}s, it fires a query like this:

SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id0 FROM (%originalQuery%) dctrn_result) dctrn_table

an getIterator() does something similar for joined collections to get the ids in the first place:

SELECT DISTINCT id0, lastmod11 FROM (%originalQuery%) dctrn_result ORDER BY lastmod11 DESC LIMIT 10 OFFSET 0

My problem is that both the inner queries can be too heavy for a regular temporary table.

At first sight I noticed several LEFT JOIN s that could be stripped from the inner query without changing the result of the outer one. But that might have been a specially easy case, a general optimisation of the JOIN clauses might be harder. I think http://www.doctrine-project.org/jira/browse/DDC-2381 deals with that.

On second thought we noticed some ugly BLOB columns as part of the projection, which unhealthily bloated the temporary table. Ultimately, the BLOBs are needed for the paginated view, but they are neither needed for counting nor for getting the paginated ids.

Hence, I propose to remove unused columns from the projection in the inner queries. "Unused" means not being part of the SELECT or ORDER BY clause in the outer query (and maybe not part of GROUP BY, HAVING... - haven't checked on this yet). The key could be the $innerSql in the LimitSubqueryOutputWalker->walkSelectStatement(), but before investigating further, I'd like to hear from you what you think.



 Comments   
Comment by Marco Pivetta [ 31/Mar/15 ]

Please review https://github.com/doctrine/doctrine2/pull/1353, as it might solve this issue

Comment by Malte Wunsch [ 31/Mar/15 ]

Thanks for your quick reply!

To be honest, I don't fully get the PR. At least it's goals look very different to me. Anyway, in LimitSubqueryOutputWalker the $innerSQL is now being generated in getInnerSQL(). In there, some hiddenAliasResultVariable are set to false (and are later restored) so that the parent SQLWalker can reference selected fields better. This might be a requirement for implementing my idea, but as far as I understand, there are no columns removed from the select clause so far?

Comment by Doctrine Bot [ 31/Mar/15 ]

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

Comment by Marco Pivetta [ 06/Apr/15 ]

Malte Wunsch the PR is actually related as it affects the selected fields.

Consider checking again against 2.5.0, as we indeed fixed many paginator issues, and this issue needs to be re-validated.

Comment by Malte Wunsch [ 07/Apr/15 ]

Great! I'll be glad to check. It might take some time, as we currently only have PHP 5.3 at our disposal (please don't tell anybody), and Doctrine 2 ORM 2.5.0 requires at least PHP 5.4. Fortunately, this is a very good trigger to put some pressure on the PHP upgrade process. I'll keep my eye on it.

Comment by Malte Wunsch [ 10/Apr/15 ]

Marco Pivetta Unfortunately, Doctrine 2.5 had no effect on my inner original query. It still looks like this:

SELECT 
  COUNT(*) AS dctrn_count 
FROM 
  (
    SELECT 
      DISTINCT id0 
    FROM 
      (
        SELECT 
          [all fields from t0_],
          [all fields from t1_],
          [all fields from t2_],
          [all fields from t3_]
        FROM 
          table1 t0_ 
          LEFT JOINs...
        WHERE 
          ...
        ORDER BY 
          ...
      ) dctrn_result
  ) dctrn_table

Just to be clear, my point is with the most inner query. If I'm correct it is generated in LimitSubqueryOutputWalker->getInnerSql(). In the special case with the query above, one could simplify it by dropping the order clause, removing the left joins and selecting only the id0 field. I have no plan for inner joins and other more complex optimisations, but I guess that removing the unused fields from the select clause might be in reach.

Comment by Matthias Pigulla [ 10/Apr/15 ]

When removing fields from the SELECT clause, we need to keep those that are referenced from GROUP BY or HAVING clauses (when ORDER BY is dropped).

Comment by Matthias Pigulla [ 14/Apr/15 ]

http://www.doctrine-project.org/jira/browse/DDC-2381 seems to be related or identical.





[DDC-2838] Leaky abstraction when applying Criteria to hydrated/non-hydrated PersistentCollection Created: 03/Dec/13  Updated: 14/Apr/15

Status: Reopened
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.4.1
Fix Version/s: None

Type: Bug Priority: Major
Reporter: brian ridley Assignee: Marco Pivetta
Resolution: Unresolved Votes: 2
Labels: None

Attachments: File DDC2838Test.php    
Issue Links:
Reference
is referenced by DCOM-275 Collections\Expr\ClosureExpressionVis... Open
is referenced by DCOM-249 Criteria are unable to locate getters... Open

 Description   

When applying a Criteria to a PersistentCollection that has been hydrated the field names must be camel case, if the collection has not yet been hydrated the field names must be underscore separated.

The github repo linked here contains a simplified testcase for the matrix of hydrated/non-hydrated entities and camel case/underscore separated fields.

https://github.com/ptlis/DoctrineTestcase



 Comments   
Comment by Marco Pivetta [ 18/Aug/14 ]

We can't check out an entire project just to test a bug.

Please write an actual functional test case that can be integrated into the Doctrine ORM test suite.

Comment by brian ridley [ 20/Aug/14 ]

Hi,

i'm happy to do so - i'll take a look at this over the weekend.

Comment by Simon Paridon [ 12/Dec/14 ]

brian ridley: Any progress on this? This is currently an issue for us as well and hope to get fixed. I could look into converting it to a test for integration with the test suite if you don't have the time... but it might take a while since I have no experience with the requirements that should be met. (Plus, I am not sure how tightly coupled it is with your project)

Comment by Simon Paridon [ 17/Dec/14 ]

Hi Marco Pivetta, brian ridley,

I attached a functional Test that integrates with the test suite. Please let me know if I should issue a PR, and I'll do that this evening.

Comment by Florian Preusner [ 26/Dec/14 ]

+1





[DDC-3686] cascade with inheritence objects Created: 12/Apr/15  Updated: 13/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: Git Master
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: sky diablo Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

this is just a dummy text, i create a unittest-case to demonstrate the issue. so i need this DDC-Number for...



 Comments   
Comment by sky diablo [ 13/Apr/15 ]

hmmm.. i have create a new unittest with my issue, but no error :| i will add some more tests and give here a sign later...

Comment by sky diablo [ 13/Apr/15 ]

i have create a new unittest in my doctrine2 ORM fork: https://github.com/skydiablo/doctrine2/blob/master/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3686Test.php all works fine, but in my real enviroment, it dosnt, here the effected code:

class Dossier {

    /**
     * @ORM\ManyToOne(targetEntity="Reference", cascade={"all"})
     * @ORM\JoinColumn(name="reference_id", referencedColumnName="id")
     */
    private $reference;
}

class Reference {

    /**
     * @ORM\ManyToOne(targetEntity="Company", cascade={"all"})
     * @ORM\JoinColumn(name="company_id", referencedColumnName="id", nullable=true)
     */
    private $company;
}

/**
 * Class ParticipantObject
 *
 * @ORM\Entity()
 * @ORM\Table(name="company_participant_object")
 * @ORM\InheritanceType(value="JOINED")
 * @ORM\DiscriminatorColumn(name="discriminator", type="string", length=45)
 * @ORM\DiscriminatorMap({
 *      "company" = "Company"
 * })
 */
abstract class ParticipantObject {

}

class Company extends ParticipantObject {

    /**
     * @ORM\ManyToOne(targetEntity="CompanyData", cascade={"all"})
     * @ORM\JoinColumn(name="company_data_id", referencedColumnName="id")
     */
    private $companyData;
}

class CompanyData {

    /**
     * @ORM\Column(name="name", type="string", length=255, nullable=false)
     */
    private $name = '';
}

all classes are annotated with a entity and table declaration. so this entitys should be the same as in my unittest. but in my real enviroment, the "company_id" in the "reference" object will never persist? and i do not know why ??? all other entitys are saved, the new "company" entity is persist ans stored in the database with the "CompanyData" and "ParticipantObject", all works fine... all data available in the database, but the "company_id" in the "reference" object is missing .... ahhhhhhh !!! whats wrong ?





[DDC-3688] Order By column doesn't have number suffix in Paginator Created: 13/Apr/15  Updated: 13/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: DQL, ORM
Affects Version/s: 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Thomas Koch Assignee: Guilherme Blanco
Resolution: Unresolved Votes: 1
Labels: None


 Description   
An exception occurred while executing 'SELECT DISTINCT IDuser_16 FROM (SELECT a0_.username AS username_0, a0_.username_canonical AS username_canonical_1, a0_.email AS email_2, a0_.email_canonical AS email_canonical_3, a0_.enabled AS enabled_4, a0_.salt AS salt_5, a0_.password AS password_6, a0_.last_login AS last_login_7, a0_.locked AS locked_8, a0_.expired AS expired_9, a0_.expires_at AS expires_at_10, a0_.confirmation_token AS confirmation_token_11, a0_.password_requested_at AS password_requested_at_12, a0_.roles AS roles_13, a0_.credentials_expired AS credentials_expired_14, a0_.credentials_expire_at AS credentials_expire_at_15, a0_.IDuser AS IDuser_16, a0_.uname AS uname_17, a0_.uprename AS uprename_18, a0_.status AS status_19, a0_.FKIDare AS FKIDare_20, a0_.IDparent AS IDparent_21 FROM aus2_users a0_ WHERE a0_.status IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)) dctrn_result ORDER BY a0_.username ASC LIMIT 10 OFFSET 0' with params [1, 2, 5, 6, 8, 9, 10, 11, 12, 13, 14]:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'a0_.username' in 'order clause'

Stacktrace: 
[1] Doctrine\DBAL\Exception\InvalidFieldNameException: An exception occurred while executing 'SELECT DISTINCT IDuser_16 FROM (SELECT a0_.username AS username_0, a0_.username_canonical AS username_canonical_1, a0_.email AS email_2, a0_.email_canonical AS email_canonical_3, a0_.enabled AS enabled_4, a0_.salt AS salt_5, a0_.password AS password_6, a0_.last_login AS last_login_7, a0_.locked AS locked_8, a0_.expired AS expired_9, a0_.expires_at AS expires_at_10, a0_.confirmation_token AS confirmation_token_11, a0_.password_requested_at AS password_requested_at_12, a0_.roles AS roles_13, a0_.credentials_expired AS credentials_expired_14, a0_.credentials_expire_at AS credentials_expire_at_15, a0_.IDuser AS IDuser_16, a0_.uname AS uname_17, a0_.uprename AS uprename_18, a0_.status AS status_19, a0_.FKIDare AS FKIDare_20, a0_.IDparent AS IDparent_21 FROM aus2_users a0_ WHERE a0_.status IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)) dctrn_result ORDER BY a0_.username ASC LIMIT 10 OFFSET 0' with params [1, 2, 5, 6, 8, 9, 10, 11, 12, 13, 14]:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'a0_.username' in 'order clause'
    at n/a
        in /home/dev/git/comsolit/kurad/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 71

    at Doctrine\DBAL\Driver\AbstractMySQLDriver->convertException('An exception occurred while executing 'SELECT DISTINCT IDuser_16 FROM (SELECT a0_.username AS username_0, a0_.username_canonical AS username_canonical_1, a0_.email AS email_2, a0_.email_canonical AS email_canonical_3, a0_.enabled AS enabled_4, a0_.salt AS salt_5, a0_.password AS password_6, a0_.last_login AS last_login_7, a0_.locked AS locked_8, a0_.expired AS expired_9, a0_.expires_at AS expires_at_10, a0_.confirmation_token AS confirmation_token_11, a0_.password_requested_at AS password_requested_at_12, a0_.roles AS roles_13, a0_.credentials_expired AS credentials_expired_14, a0_.credentials_expire_at AS credentials_expire_at_15, a0_.IDuser AS IDuser_16, a0_.uname AS uname_17, a0_.uprename AS uprename_18, a0_.status AS status_19, a0_.FKIDare AS FKIDare_20, a0_.IDparent AS IDparent_21 FROM aus2_users a0_ WHERE a0_.status IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)) dctrn_result ORDER BY a0_.username ASC LIMIT 10 OFFSET 0' with params [1, 2, 5, 6, 8, 9, 10, 11, 12, 13, 14]:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'a0_.username' in 'order clause'', object(PDOException))
        in /home/dev/git/comsolit/kurad/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php line 116

    at Doctrine\DBAL\DBALException::driverExceptionDuringQuery(object(Driver), object(PDOException), 'SELECT DISTINCT IDuser_16 FROM (SELECT a0_.username AS username_0, a0_.username_canonical AS username_canonical_1, a0_.email AS email_2, a0_.email_canonical AS email_canonical_3, a0_.enabled AS enabled_4, a0_.salt AS salt_5, a0_.password AS password_6, a0_.last_login AS last_login_7, a0_.locked AS locked_8, a0_.expired AS expired_9, a0_.expires_at AS expires_at_10, a0_.confirmation_token AS confirmation_token_11, a0_.password_requested_at AS password_requested_at_12, a0_.roles AS roles_13, a0_.credentials_expired AS credentials_expired_14, a0_.credentials_expire_at AS credentials_expire_at_15, a0_.IDuser AS IDuser_16, a0_.uname AS uname_17, a0_.uprename AS uprename_18, a0_.status AS status_19, a0_.FKIDare AS FKIDare_20, a0_.IDparent AS IDparent_21 FROM aus2_users a0_ WHERE a0_.status IN (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)) dctrn_result ORDER BY a0_.username ASC LIMIT 10 OFFSET 0', array('1', '2', '5', '6', '8', '9', '10', '11', '12', '13', '14'))
        in /home/dev/git/comsolit/kurad/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php line 836

    at Doctrine\DBAL\Connection->executeQuery('SELECT DISTINCT IDuser_16 FROM (SELECT a0_.username AS username_0, a0_.username_canonical AS username_canonical_1, a0_.email AS email_2, a0_.email_canonical AS email_canonical_3, a0_.enabled AS enabled_4, a0_.salt AS salt_5, a0_.password AS password_6, a0_.last_login AS last_login_7, a0_.locked AS locked_8, a0_.expired AS expired_9, a0_.expires_at AS expires_at_10, a0_.confirmation_token AS confirmation_token_11, a0_.password_requested_at AS password_requested_at_12, a0_.roles AS roles_13, a0_.credentials_expired AS credentials_expired_14, a0_.credentials_expire_at AS credentials_expire_at_15, a0_.IDuser AS IDuser_16, a0_.uname AS uname_17, a0_.uprename AS uprename_18, a0_.status AS status_19, a0_.FKIDare AS FKIDare_20, a0_.IDparent AS IDparent_21 FROM aus2_users a0_ WHERE a0_.status IN (?)) dctrn_result ORDER BY a0_.username ASC LIMIT 10 OFFSET 0', array(array('1', '2', '5', '6', '8', '9', '10', '11', '12', '13', '14')), array('102'), null)
        in /home/dev/git/comsolit/kurad/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php line 50

    at Doctrine\ORM\Query\Exec\SingleSelectExecutor->execute(object(Connection), array(array('1', '2', '5', '6', '8', '9', '10', '11', '12', '13', '14')), array('102'))
        in /home/dev/git/comsolit/kurad/vendor/doctrine/orm/lib/Doctrine/ORM/Query.php line 321

    at Doctrine\ORM\Query->_doExecute()
        in /home/dev/git/comsolit/kurad/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 969

    at Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(null, '3')
        in /home/dev/git/comsolit/kurad/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 924

    at Doctrine\ORM\AbstractQuery->execute(null, '3')
        in /home/dev/git/comsolit/kurad/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php line 751

    at Doctrine\ORM\AbstractQuery->getScalarResult()
        in /home/dev/git/comsolit/kurad/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Pagination/Paginator.php line 151

    at Doctrine\ORM\Tools\Pagination\Paginator->getIterator()
        in  line 

    at iterator_to_array(object(Paginator))

I use the doctrine paginator on a normal FosUserBundle user entity. It worked with doctrine-common 2.4.2, -orm 2.4.7 and throws this exception with doctrine 2.5.

While I stepped through the code with xdebug I got this notice once, but I can't reproduce it anymore:

Notice: Undefined property: Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker::$queryComponents in vendor/doctrine/orm/lib/Doctrine/ORM/Query/SqlWalker.php at line 1369

with this stacktrace:

at SqlWalker ->walkSelectExpression (object(SelectExpression)) 
at array_map (array(object(LimitSubqueryOutputWalker), 'walkSelectExpression'), array(object(SelectExpression))) 
in vendor/doctrine/orm/lib/Doctrine/ORM/Query/SqlWalker.php at line 699   + 
at SqlWalker ->walkSelectClause (object(SelectClause)) 
in vendor/doctrine/orm/lib/Doctrine/ORM/Query/SqlWalker.php at line 521   + 
at SqlWalker ->walkSelectStatement (object(SelectStatement)) 
in vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php at line 492   + 
at LimitSubqueryOutputWalker ->getInnerSQL (object(SelectStatement)) 
in vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php at line 271   + 
at LimitSubqueryOutputWalker ->walkSelectStatementWithoutRowNumber (object(SelectStatement), false) 
in vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php at line 319   + 
at LimitSubqueryOutputWalker ->addMissingItemsFromOrderByToSelect (object(SelectStatement)) 
in vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php at line 263   + 
at LimitSubqueryOutputWalker ->walkSelectStatementWithoutRowNumber (object(SelectStatement)) 
in vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php at line 184   + 
at LimitSubqueryOutputWalker ->walkSelectStatement (object(SelectStatement)) 
in vendor/doctrine/orm/lib/Doctrine/ORM/Query/Exec/SingleSelectExecutor.php at line 42   + 
at SingleSelectExecutor ->__construct (object(SelectStatement), object(LimitSubqueryOutputWalker)) 
in vendor/doctrine/orm/lib/Doctrine/ORM/Query/SqlWalker.php at line 277   + 
at SqlWalker ->getExecutor (object(SelectStatement)) 
in vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php at line 390   + 
at Parser ->parse () 
in vendor/doctrine/orm/lib/Doctrine/ORM/Query.php at line 281   + 
at Query ->_parse () 
in vendor/doctrine/orm/lib/Doctrine/ORM/Query.php at line 293   + 
at Query ->_doExecute () 
in vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php at line 969   + 
at AbstractQuery ->executeIgnoreQueryCache (null, '3') 
in vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php at line 924   + 
at AbstractQuery ->execute (null, '3') 
in vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php at line 751   + 
at AbstractQuery ->getScalarResult () 
in vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Pagination/Paginator.php at line 151   + 
at Paginator ->getIterator () 
at iterator_to_array (object(Paginator)) 
in src/Comsolit/KuradBundle/Util/PaginatorJsonResponse.php at line 76   + 

Maybe this is related to DDC-3434?



 Comments   
Comment by Thomas Koch [ 13/Apr/15 ]

Our user class has a relation to another entity:

     /**
     * @ORM\ManyToOne(targetEntity="Organization", fetch="EAGER")
     * @ORM\JoinColumn(name="id", referencedColumnName="organization_id", nullable=true)
     * @var \Comsolit\EntityOrganization
     */
    private $organization;




[DDC-3684] [GH-1381] Fixes ClassMetadata wakeupReflection with embeddable and StaticReflectio... Created: 11/Apr/15  Updated: 13/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

...nService

When the `StaticReflectionService` is used, then the wakeupReflection will cause an error with embedded properties. This is because the `getAccessibleProperty` method of the `StaticReflectionService` will always return null, so the parentReflFields will only have null values.

I found this problem when I was generating a Symfony form based on an entity with embedded properties.



 Comments   
Comment by Doctrine Bot [ 13/Apr/15 ]

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

Comment by Doctrine Bot [ 13/Apr/15 ]

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





[DDC-3685] wrong bit check ? Created: 12/Apr/15  Updated: 12/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: Git Master
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: sky diablo Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

this is just a hint:

https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/UnitOfWork.php#L716

i think it is a good idea to use a bit save check, like:

if (($assoc['type'] & ClassMetadata::TO_ONE) == ClassMetadata::TO_ONE) {






[DDC-3683] [GH-1380] Fix issue with second-level-cache tests and versioned entities Created: 10/Apr/15  Updated: 10/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Second Level Cache
Affects Version/s: Git Master
Fix Version/s: None
Security Level: All

Type: Bug Priority: Minor
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: cache, testing, version

Issue Links:
Dependency
is required for DDC-3681 [GH-1378] Feature to force-increment ... Awaiting Feedback

 Description   

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

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

Message:

I'm not sure why this bug doesn't show normally `master`, but I ran across it with build [3930.1](https://travis-ci.org/doctrine/doctrine2/jobs/57975906), where it complained since `$targetPersister` was not an instance of `CachedPersister`.

The immediate fix seems straightforward, because `DefaultCollectionHydrator` doesn't even accept the second argument.

@FabioBatSilva : Please let me know if you see some better resolution to this, or if it indicates some edge-case in the second-level-cache logic that requires a new test.






[DDC-3681] [GH-1378] Feature to force-increment entity version Created: 09/Apr/15  Updated: 10/Apr/15

Status: Awaiting Feedback
Project: Doctrine 2 - ORM
Component/s: Mapping Drivers, ORM
Affects Version/s: Git Master
Fix Version/s: None
Security Level: All

Type: New Feature Priority: Minor
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: persister, unitofwork, versioned

Issue Links:
Dependency
depends on DDC-3683 [GH-1380] Fix issue with second-level... Open
Duplicate
is duplicated by DDC-3640 Force version increment via mapped pr... Resolved

 Description   

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

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

Message:

Submitting for feedback and experimentation.

The major use-case for this involves using certain entities as the versioned-gatekeepers for changes that don't directly live on the same entity. For example, using the version of a `PurchaseOrder` to control changes to any of its child `PurchaseOrderLineItem` objects.






[DDC-3481] [GH-1241] [3.0] [POC] lazy-load on a per-property base Created: 09/Jan/15  Updated: 09/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Reference
is referenced by DCOM-282 Use call_user_func_array in proxy cla... Open

 Description   

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

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

Message:

This is just a proof of concept that I hacked together real quick.

This changes how proxies are generated and lazy-loaded in a very radical way:

  • method calls do not cause lazy-loading
  • lazy-loading is triggered by access to non-transient properties (things that need to be lazy-loaded)
  • access to identifiers or non-mapped properties won't cause lazy-loading

Following BC breaks need to be fixed or discussed before going forward on this idea:

  • [ ] proxies don't implement `Doctrine\Common\Proxy\Proxy` anymore, but `ProxyManager\Proxy\GhostObjectInterface` (BC break, needs fixing, can be easily done with some effort)
  • [ ] `serialize($proxy)` now causes proxy initialization (probably needs fixing, as this is a major BC break)

Pending TODOs:

  • [ ] cloning a proxy is still not fully supported (requires dedicated logic in `__clone`)
  • [ ] this is just a PoC, so the code that writes proxies to disk is not yet in place


 Comments   
Comment by Doctrine Bot [ 24/Jan/15 ]

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

Comment by Doctrine Bot [ 24/Jan/15 ]

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





[DDC-3679] Paginator generates broken SQL when paginating ordered query Created: 08/Apr/15  Updated: 09/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: DQL
Affects Version/s: 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Filip Procházka Assignee: Guilherme Blanco
Resolution: Unresolved Votes: 1
Labels: dql, mysql, orm


 Description   

I have a following DQL

SELECT ra FROM Damejidlo\Recipes\RecipeAuthor ra ORDER BY ra.id ASC

Which generates following SQL

SELECT r0_.id AS id_0, r0_.name AS name_1, r0_.perex AS perex_2, r0_.is_active AS is_active_3, r0_.on_homepage AS on_homepage_4, r0_.content AS content_5, r0_.photo AS photo_6, r0_.link AS link_7 FROM recipes_authors r0_ ORDER BY r0_.id ASC

Now I wanna paginate it

$query = $em->createQuery($dql);
$paginated = new \Doctrine\ORM\Tools\Pagination\Paginator($query, TRUE);

the generated SQL Count query is

SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id_0 FROM (SELECT r0_.id AS id_0, r0_.name AS name_1, r0_.perex AS perex_2, r0_.is_active AS is_active_3, r0_.on_homepage AS on_homepage_4, r0_.content AS content_5, r0_.photo AS photo_6, r0_.link AS link_7 FROM recipes_authors r0_ ORDER BY r0_.id ASC) dctrn_result) dctrn_table

Next executed query is the query that selects ids for where in

SELECT DISTINCT id_0 FROM (SELECT r0_.id AS id_0, r0_.name AS name_1, r0_.perex AS perex_2, r0_.is_active AS is_active_3, r0_.on_homepage AS on_homepage_4, r0_.content AS content_5, r0_.photo AS photo_6, r0_.link AS link_7 FROM recipes_authors r0_) dctrn_result ORDER BY r0_.id ASC LIMIT 5 OFFSET 0

And there goes my problem

Doctrine\DBAL\Exception\InvalidFieldNameException

An exception occurred while executing '...': SQLSTATE[42S22]: Column not found: 1054 Unknown column 'r0_.id' in 'order clause'

I'm going to investigate more, I just wanned to open an issue for now so you're aware.



 Comments   
Comment by Filip Procházka [ 08/Apr/15 ]
aa80c7d!orm $> bisect start
aa80c7d!orm $> bisect bad
aa80c7d!orm $> bisect good v2.4.7
Bisecting: a merge base must be tested
[29d6da0fa063d55d06117045f3446b2716202d2b] Merge pull request #703 from shulcsm/patch-1
29d6da0!orm $> bisect good
Bisecting: 912 revisions left to test after this (roughly 10 steps)
[a2e0133a94bf235498ee2e805c8ca9a147b7fa24] Adding DDC-3276 test group
a2e0133!orm $> bisect good
Bisecting: 456 revisions left to test after this (roughly 9 steps)
[dde09872df4f442f3a2a4c9ce6053badb8b49012] #1172 - writing a more concise test case about merging detached proxies
dde0987!orm $> bisect good
Bisecting: 233 revisions left to test after this (roughly 8 steps)
[d024193cc0d106d4939bbf698f840ef122602d64] Merge pull request #1272 from Ocramius/hotfix/DDC-2704-merge-inherited-transient-properties
d024193!orm $> bisect good
Bisecting: 116 revisions left to test after this (roughly 7 steps)
[6cf76158a07219529631f7b8fb43c3b92d3552be] Merge pull request #1329 from Wilt/patch-1
6cf7615!orm $> bisect good
Bisecting: 58 revisions left to test after this (roughly 6 steps)
[d1a695b42b54ed7deb2f9461fee7d02d32514c3a] Typo in phpdoc
d1a695b!orm $> bisect good
Bisecting: 28 revisions left to test after this (roughly 5 steps)
[b923c937e2194ae38c88e31cfcea8d06b58603fc] Merge branch 'hotfix/#1352-entity-generator-new-class-metadata-hotfix'
b923c93!orm $> bisect good
Bisecting: 14 revisions left to test after this (roughly 4 steps)
[6c5dbd8d4ca4fd68f0d5b2de467c3d2a59e0173c] #1353 #1347 #1351 - Removing double quotes (confusing)
6c5dbd8!orm $> bisect bad
Bisecting: 6 revisions left to test after this (roughly 3 steps)
[af3f5c5c5a93daf240c2daae4eddf9a0628eeb19] Add test for paginating on a query with a subquery in the where clause
af3f5c5!orm $> bisect good
Bisecting: 3 revisions left to test after this (roughly 2 steps)
[b76107e20f7fa893c2e4945a373ff624ed00c0d2] resolve review comments from @stof
b76107e!orm $> bisect bad
Bisecting: 0 revisions left to test after this (roughly 1 step)
[edcc0fc024e0d33a4f6159c006c0f393386dac3a] Fix paginator when ordering by while selecting entities using joined table inheritance
edcc0fc!orm $> bisect bad
Bisecting: 0 revisions left to test after this (roughly 0 steps)
[09d28819b520b9219bd6f41e8c6e0f4449a3807b] Fix issue where paginating on a query with a subquery in the where clause crashed
09d2881!orm $> bisect good
edcc0fc024e0d33a4f6159c006c0f393386dac3a is the first bad commit
commit edcc0fc024e0d33a4f6159c006c0f393386dac3a
Author: Bill Schaller <bill@zeroedin.com>
Date:   Mon Mar 30 12:16:50 2015 -0400

    Fix paginator when ordering by while selecting entities using joined table inheritance

:040000 040000 aa2bd1b6cb6dc10ef39c3ea1affe78c75bb2b778 4dc9a0e15f847bfc940096263a639d6f1a4eb618 M      lib
:040000 040000 fa9a72d3eaae021b0015e43bbe64a9cf7eadf46e 7b6821dd22bee36c808e4680a427aa3ec75faad0 M      tests
09d2881!orm $>
Comment by Filip Procházka [ 08/Apr/15 ]

I've narrowed down the problem to this piece of code

lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php
+            $fieldMapping = $class->fieldMappings[$columnName];
+            if (isset($fieldMapping['declared']) && $fieldMapping['declared'] !== $class->name) {
+                // Field was declared in a parent class, so we need to get the proper SQL table alias
+                // for the joined parent table.
+                $otherClassMetadata = $this->_em->getClassMetadata($fieldMapping['declared']);
+                $sqlTableAliasForFieldAlias = $this->getSQLTableAlias($otherClassMetadata->getTableName(), $dqlAliasForFieldAlias);
+            }

This breaks the searchPatterns map

Because it thinks it needs to use different table alias for mapped superclass that contains the `id` property.

Comment by Filip Procházka [ 08/Apr/15 ]

I've opened a pullrequest with failing test case https://github.com/doctrine/doctrine2/pull/1377

Comment by Doctrine Bot [ 08/Apr/15 ]

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

Comment by Doctrine Bot [ 08/Apr/15 ]

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

Comment by Doctrine Bot [ 09/Apr/15 ]

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





[DDC-3647] [GH-1354] [RFC] Added support for OneToMany with orphanRemoval. Created: 01/Apr/15  Updated: 08/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

Replacing entire collection now deletes the replaced collection (scheduled for deletion). No event handling is done as it happens at DBAL level.

Fixes DDC-3644



 Comments   
Comment by Doctrine Bot [ 08/Apr/15 ]

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

Comment by Doctrine Bot [ 08/Apr/15 ]

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

Comment by Doctrine Bot [ 08/Apr/15 ]

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





[DDC-3635] QueryBuilder - INSTANCE OF with parameter not working Created: 24/Mar/15  Updated: 08/Apr/15

Status: Reopened
Project: Doctrine 2 - ORM
Component/s: DQL
Affects Version/s: 2.4.7
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Wouter Wiltenburg Assignee: Guilherme Blanco
Resolution: Unresolved Votes: 0
Labels: binding, dql, parameter
Environment:

Zend Framework 2



 Description   

I use single table class inheritance.
When I write my INSTANCE OF clause in my QueryBuilder like this:

    $result = $this->createQueryBuilder('o')
        ->leftJoin('o.child', 'c')
        ->where('c INSTANCE OF :entity_class')
        ->setParameter('entity_class', 'My\Entity\Class')
        ->getQuery()
        ->getResult();

It does not work correctly. The problem seems to lie in the fact that the parameter is bound to the SQL query. So if I change the entity_class to the discriminator column name it works correctly.

So if the discriminator value for My\Entity\Class would be discriminator then this does work:

    $result = $this->createQueryBuilder('o')
        ->leftJoin('o.child', 'c')
        ->where('c INSTANCE OF :entity_class')
        ->setParameter('entity_class', 'discriminator')
        ->getQuery()
        ->getResult();

So the step for getting the discriminator column from the class name is missing and instead the class name is bound to the MySql query directly.



 Comments   
Comment by Guilherme Blanco [ 08/Apr/15 ]

INSTANCE OF expressions expect either their class names or their corresponding class metadata. This means the following examples are valid:

$qb->where('c INSTANCE OF My\Entity\Class');

// or

$qb
    ->where('c INSTANCE OF :param')
    ->setParameter('param', $em->getClassMetadata('My\Entity\Class'))
;

Assigning class name directly does not work.
Closing as invalid.

Comment by Marco Pivetta [ 08/Apr/15 ]

Re-opening. I think this is a documentation issue then, as http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#id2 says that the InstanceOfParameter accepts also an InputParameter

Comment by Guilherme Blanco [ 08/Apr/15 ]

Marco Pivetta And it does. However, the bound parameter must be a ClassMetadata.





[DDC-3671] Duplicated unique indexes (@UniqueConstraint annotation) Created: 07/Apr/15  Updated: 08/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Tools
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Michał Bundyra Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: duplicate, index, schema-tool

Issue Links:
Duplicate
is duplicated by DDC-3677 [GH-1375] DDC-3671 prevent duplicate ... Open

 Description   

In this commit:
https://github.com/doctrine/dbal/commit/fc8beca08600b44e46f7b82998adbcc6d52c31f1
was changed to not checking for if index already exists. After that occur problem with duplicated unique keys (for example migrations try add unique index on the same columns with different index name).

This is an example model:

/**
 * @Entity
 * @Table(name="double_uniq_index_table", uniqueConstraints={
 *   @UniqueConstraint(name="uniq_hash", columns={"hash"})
 * })
 */
class DoubleUniqIndexModel
{
    /** @Id @Column */
    private $id;

    /** @Column(name="hash", type="string", length=8, nullable=false, unique=true) */
    private $hash;
}

and the basic test:

    public function testDoubleUniqIndex()
    {
        $em = $this->_getTestEntityManager();
        $schemaTool = new SchemaTool($em);

        $classes = array(
            $em->getClassMetadata(__NAMESPACE__ . '\\DoubleUniqIndexModel'),
        );

        $schema = $schemaTool->getSchemaFromMetadata($classes);

        $this->assertTrue($schema->hasTable('double_uniq_index_table'));
        $this->assertEquals(2, count($schema->getTable('double_uniq_index_table')->getIndexes()));
    }

(I've added it into: tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php).

Test failures, because generated schema contains three indexes (primary, and two unique on the same column with different names - one auto generated uniq_* and one provided in annotations - uniq_hash).






[DDC-3677] [GH-1375] DDC-3671 prevent duplicate unique index Created: 08/Apr/15  Updated: 08/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Duplicate
duplicates DDC-3671 Duplicated unique indexes (@UniqueCon... Open

 Description   

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

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

Message:






[DDC-3674] Additional informations when closing EntityManager Created: 08/Apr/15  Updated: 08/Apr/15

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

Type: Improvement Priority: Major
Reporter: Daniel Mecke Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: orm, unitofwork


 Description   

When the EntityManager is closed there is no way to find out why it has been closed afterwards. For example it would be nice if ORMException::entityManagerClosed() could add the information which query caused it to close. That would ease debugging a lot.
Maybe the EntityManager::close() method could get a parameter which stores the query or informations about it in a property next to the EntityManager::closed property?






[DDC-3672] After update to 2.5.0 we need left join to order correctly with pagination Created: 07/Apr/15  Updated: 07/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Guilherme Santos Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None
Environment:

MySQL 5.6



 Description   

Before update to 2.5.0 I had follow code working:

$qb = $this->_em->createQueryBuilder()->select('customer')->from('Test\Entity\Customer', 'customer');
$qb->addOrderBy('customer.person', 'ASC');
$paginator = new Paginator($query);
var_dump($paginator->getIterator());

As workaround I had to add:

$qb->leftJoin('customer.person', 'person');
// and update orderBy to
$qb->addOrderBy('person.id', 'ASC');


 Comments   
Comment by Marco Pivetta [ 07/Apr/15 ]

Does

ORDER BY IDENTITY(customer.person)

work?

Comment by Guilherme Santos [ 07/Apr/15 ]

Nop, same error..
Sorry, I don't tell you the error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'c0_.person_id' in 'order clause'
Comment by Christophe Coevoet [ 07/Apr/15 ]

Marco Pivetta Looks like we are still missing a bunch of functional tests for the pagination

Comment by Marco Pivetta [ 07/Apr/15 ]

Christophe Coevoet yeah, a whole lot of them :-\





[DDC-3652] Problem with joins between entities without associations Created: 02/Apr/15  Updated: 06/Apr/15

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

Type: Bug Priority: Major
Reporter: Eunice Valdez Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Reference
relates to DDC-3410 Allow Query Builder to specify the jo... Open

 Description   

I needed to write a DQL query that selects an entity that is not specified in the FROM part. For that I am using joins between entities without associations. But I found a problem. Let me explain it with the following example:

Here the query I wrote

            SELECT l
            FROM Label l
            JOIN l.product_labels pl
            JOIN pl.product p
            JOIN creams.c WITH c.product = p
            WHERE c.type = 'general_cleaners'
            AND l.name = "Eye cleaners"

This is translated to SQL as:

SELECT 
  l0_.id AS id0, 
  l0_.name AS name1, 
FROM 
  label l0_ 
  INNER JOIN product_label p1_ ON l0_.id = p1_.label_id 
  INNER JOIN product p2_ ON p1_.product_id = p2_.id 
  INNER JOIN creams c3_ 
  AND (c3_.product = p2_.id)  <---- this should be in the WHERE part!
WHERE 
  c3_.type = 'general_cleaners'
 AND l0_.name "Eye cleaners"

What happens is that the query gets all the products with the label "Eye cleaners" and the creams having that belong to those products. But it never filters out the products that have no cream association.

To go around the problem I added the condition

AND c.product = p.id

in the WHERE clause in the DQL query

After searching for the issue I found something related but no the same. So i decided to put my findings under your consideration.

Thanks a lot



 Comments   
Comment by Marco Pivetta [ 06/Apr/15 ]
AND (c3_.product = p2_.id)  <---- this should be in the WHERE part!

Why should it go in the WHERE clause? You specified it on a join WITH condition, which in ORM terms translates to an additional ON clause





[DDC-3661] Doctrine\ORM\LazyCriteriaCollection unpredictable count() Created: 04/Apr/15  Updated: 06/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Fedir Zinchuk Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: count, lazy, lazy-criteria-collection, lazy-loading, orm

Issue Links:
Dependency
is required for DDC-3668 [GH-1372] [DDC-3661] Fix count in Doc... Open

 Description   

When criteria has set $maxResults Doctrine\ORM\LazyCriteriaCollection::count() can return different result depend when it was called, before initialize() or after.

When LazyCriteriaCollection not initialized then count() return Total from database,
when LazyCriteriaCollection have been initialized then count() return Total from "collection" that is limited by Criteria::$maxResults.

Example you have 30 items in database and Criteria::$maxResults = 5, then:

$items = $repositiry->matching($criteria);
var_dump($items->count()); // will show 30 items
$items->toArray();
var_dump($items->count()); // will show 5 items

It is very confuse

also I not sure which behaviour is right: it should always return Total from database or Total depend from Criteria::$maxResults



 Comments   
Comment by Marco Pivetta [ 04/Apr/15 ]

This is indeed a bug: consider writing an example test case so that we can work on it.

Comment by Fedir Zinchuk [ 04/Apr/15 ]

I think I found solution, I try make pull request tomorrow

Comment by Fedir Zinchuk [ 05/Apr/15 ]

there it is https://github.com/doctrine/doctrine2/pull/1372

For exaple can take that docs.doctrine-project.org/en/latest/reference/working-with-associations.html#filtering-collections

For example for User entity:
if you have BirthdayUsers in database 100 and run next code:

$repositiry = $em->getRepository('User');
$criteria = Criteria::create()
    ->where(Criteria::expr()->eq("birthday", "1982-02-17"))
    ->orderBy(array("username" => Criteria::ASC))
    ->setFirstResult(0)
    ->setMaxResults(20)
;
$birthdayUsers = $repositiry->matching($criteria);
var_dump($birthdayUsers->count()); // will show 100 items
$birthdayUsers->toArray();
var_dump($birthdayUsers->count()); // will show 20 items
Comment by Doctrine Bot [ 06/Apr/15 ]

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





[DDC-3668] [GH-1372] [DDC-3661] Fix count in Doctrine\ORM\LazyCriteriaCollection Created: 05/Apr/15  Updated: 06/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Dependency
depends on DDC-3661 Doctrine\ORM\LazyCriteriaCollection u... Open

 Description   

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

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

Message:

Fix Doctrine\ORM\LazyCriteriaCollection::count() when Criteria::$maxResults defined

ps. I have no idea how to write test for it :speak_no_evil:



 Comments   
Comment by Doctrine Bot [ 06/Apr/15 ]

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





[DDC-3662] "Improve efficiency of One-To-Many EAGER" still do 2 db request when Criteria::$firstResult set Created: 04/Apr/15  Updated: 05/Apr/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Fedir Zinchuk Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

In Doctrine 2.5 when I have entity with association One-To-Many and fetch="EAGER", doctrine still do 2 db request , when use Criteria with Criteria::$firstResult and Criteria::$maxResults

last time I tested on Doctrine 2.5 RC 1, and there this have work perfect: doctrine have use JOIN to load association.

I think it get broken between 2.5 rc1 and 2.5

for load the items I use

$criteria->setFirstResult(0);// this and next, cause 2 request per item
$criteria->setMaxResults(10);
$items = $repositiry->matching($criteria);


 Comments   
Comment by Marco Pivetta [ 04/Apr/15 ]

Fedir Zinchuk could you come up with an example?

This looks like logic that goes through the paginator, if I'm not mistaken...

Comment by Fedir Zinchuk [ 05/Apr/15 ]

Example you have entities: Gallery and Image,
where Gallery have field 'images' that is bidirectional association One-To-Many and fetch="EAGER" with Image,
and you load the galleries using matching($criteria), then:

This code will do 1 db request for load Galleries list + 1 db request for each Gallery item, to load its Images

$repositiry = $em->getRepository('Gallery');
$criteria  = Criteria::create();
$criteria->where(Criteria::expr()->eq("published", 1));
$criteria->setFirstResult(0);
$criteria->setMaxResults(20);

$galleries = $repositiry->matching($criteria);

This code will do 1 db request for load All: Galleries and its Images

$repositiry = $em->getRepository('Gallery');
$criteria  = Criteria::create();
$criteria->where(Criteria::expr()->eq("published", 1));

$galleries = $repositiry->matching($criteria);

I use setFirstResult() and setMaxResults() because I use external pagination not from Doctrine.

After small investigation, I found that it because $this->currentPersisterContext->handlesLimits there https://github.com/doctrine/doctrine2/blob/e57be9da5e0c6bb31ac286d213e204784a34aa43/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php#L1221





[DDC-3561] Wrong SQL generated for Drop Foreign Key on MySQL Created: 06/Feb/15  Updated: 03/Apr/15

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

Type: Bug Priority: Major
Reporter: Stefan Gnann Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None
Environment:

operating system: osx yosemite
database driver: pdo_mysql
installed bundles:
doctrine/annotations v1.2.3
doctrine/cache v1.4.0
doctrine/collections v1.2
doctrine/common v2.4.2
doctrine/data-fixtures dev-master ac36ccc
doctrine/dbal v2.5.1
doctrine/doctrine-bundle v1.3.0
doctrine/doctrine-cache-bundle v1.0.1
doctrine/doctrine-fixtures-bundle v2.2.0
doctrine/doctrine-migrations-bundle dev-master 81575a4
doctrine/inflector v1.0.1
doctrine/instantiator 1.0.4
doctrine/lexer v1.0.1
doctrine/migrations dev-master 96f838b
doctrine/mongodb 1.1.6
doctrine/mongodb-odm dev-master 23152aa
doctrine/mongodb-odm-bundle dev-master 9748d11
doctrine/orm v2.4.7
gedmo/doctrine-extensions v2.3.9
stof/doctrine-extensions-bundle v1.1.0


Attachments: File migrate-example.php    

 Description   

i´m new to doctrine, but it seems to me that there is a problem creating statements in migrations.
Please see the //comments in the attached file!



 Comments   
Comment by Marco Pivetta [ 06/Feb/15 ]

Steve Müller I think I saw this issue already in the DBAL tracker somewhere, but I can't find it. Do you remember the issue ID?

Comment by Stefan Gnann [ 06/Feb/15 ]

The attached file was automatically generated after upgrading doctrine/dbal onto version 2.5.1 .

Now i have DOWNgraded doctrine/dbal to version 2.4.4 .
Suddenly the doctrine:migrations:diff says "No changes detected in your mapping information.".

Before downgrading i had two identical databases. One locally installed and one in a vagrant box with debian as os.
On every database i did a "doctrine:migrations:diff" to generate an actual schema update file. What i was wondering ist, that i got two different files with different ALTER xxxxx statements regarding to FOREIGN KEY and INDEXES.

Maybe this is a bug in doctrine/dbal 2.5.1?

Comment by Stefan Gnann [ 06/Feb/15 ]

actual installed bundles after downgrading:

doctrine/annotations v1.2.3
doctrine/cache v1.4.0
doctrine/collections v1.2
doctrine/common v2.4.2
doctrine/data-fixtures dev-master 80401e8
doctrine/dbal v2.4.4
doctrine/doctrine-bundle v1.3.0
doctrine/doctrine-cache-bundle v1.0.1
doctrine/doctrine-fixtures-bundle v2.2.0
doctrine/doctrine-migrations-bundle dev-master 81575a4
doctrine/inflector v1.0.1
doctrine/instantiator 1.0.4
doctrine/lexer v1.0.1
doctrine/migrations dev-master 1ac14fa
doctrine/mongodb 1.1.7
doctrine/mongodb-odm dev-master 1343375
doctrine/mongodb-odm-bundle dev-master 27e7690
doctrine/orm v2.4.7
gedmo/doctrine-extensions v2.3.11
stof/doctrine-extensions-bundle v1.1.0

Comment by Peter Rehm [ 18/Feb/15 ]

Steve Müller I did some research on that the last days and I am sure, there is still a major issue with the implementation.

The schema update creates the following sql commands:

$this->addSql('ALTER TABLE Article DROP FOREIGN KEY FK_12743CF7924C3225');
$this->addSql('ALTER TABLE Article DROP FOREIGN KEY FK_12743CF79395C3F3');
$this->addSql('ALTER TABLE Article DROP FOREIGN KEY FK_12743CF7F7C5BCDB');
$this->addSql('ALTER TABLE Article DROP FOREIGN KEY FK_93173F21A23B42D');
$this->addSql('ALTER TABLE Article DROP FOREIGN KEY FK_93173F21A5790FE9');
$this->addSql('ALTER TABLE Article ADD CONSTRAINT FK_12743CF7924C3225 FOREIGN KEY (createdUser_id) REFERENCES CoreUser (id)');

Looking at the previous SQL schema I found out that there is already e.g. the FK_12743CF7924C3225. This FK
will be dropped and newly added at the same time. It is actually not using the new FK name which doctrine would
like to see. However in the down sql it tried to drop the key which should be there.

In addition to that there is an issue with upper/lowercase Index names. This I got fixed by

return 'DROP INDEX ' . strtoupper($indexName) . ' ON ' . $table;

in MysqlPlatform:860 which is most likely not the right way. I am more concerned about the FK
issue, which I am unable to track down so far. Do you have any idea?

Comment by Peter Rehm [ 20/Mar/15 ]

@deeky666 Have you had a chance to look at this?

Comment by Marco Pivetta [ 03/Apr/15 ]

Maybe relevant, but I'm still clueless myself: https://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html





[DDC-3649] [GH-1356] Introduced skipNamespaceInPath and skipNamespacePartInPath properties Created: 01/Apr/15  Updated: 02/Apr/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

Hi All,

I've extended the EntityGenerator in order to make handling of namespaces more flexible. Currently the EntityGenerator class creates a full tree based on the namespace under the output-directory. This causes problems in a PSR-4-like environment. Thus, i've introduced two properties in order to manipulate the target path:

skipNamespaceInPath: if true, every class file is put directly into the output-directory. if false (which is the default and equal to the current behaviour), subdirectories based on the namespace are generated.

skipNamespacePartInPath: the part of the namespace to skip, for example if the namespace is 'Foo\Bar\Entities\MyEntity', and skipNamespacePartInPath is set to 'Foo\Bar', the entity MyEntity is generated in the directory 'Entities' under the output-directory.

Andreas



 Comments   
Comment by Doctrine Bot [ 01/Apr/15 ]

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

Comment by Doctrine Bot [ 02/Apr/15 ]

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





[DDC-3410] Allow Query Builder to specify the joins of Join Inheritance entities Created: 25/Nov/14  Updated: 02/Apr/15

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

Type: Improvement Priority: Minor
Reporter: Dave Newson Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Reference
is referenced by DDC-3652 Problem with joins between entities w... Open

 Description   

Possibly a duplicate of DDC-16 in essence; resolving this would probably resolve that issue.

Summary
When you SELECT an entity which is a superclass using Joined Inheritance, Doctrine automatically adds it's own JOINs of the superclass or subclass tables.
These automatic JOINs that are introduced can't be used in DQL/builder, so you can't do anything with them (further joins on their associations for eager loading, WHERE queries, etc).
Allow me to specify my own Joins between the superclass and subclass so I can perform further queries deeper in the associations.

Main culprit:
https://github.com/doctrine/doctrine2/blob/2.4/lib/Doctrine/ORM/Query/SqlWalker.php#L341

Long version
Superclass "Activity" uses the Joined inheritance type with a discriminator column. There are various activities such as ActivityDocument, ActivityTask, etc.
These sub-class activities have associations to other entities; ActivityDocument associates to a Document entity, and Document then associates to User.

For the query, I want to fetch all Activity where the Activities document/task is associated to a given user. If I wanted to do this in raw SQL it would look something like this:

SELECT a.*, ad.*, d.*, at.*, t.*
FROM Activity a
LEFT JOIN ActivityDocument ad ON ad.id = a.id
LEFT JOIN Document d ON d.id = ad.document_id
LEFT JOIN ActivityTask at ON at.id = a.id
LEFT JOIN Task t ON t.id = at.task_id
WHERE
t.user_id = 1 OR d.user_id = 1

Doctrine supports the joined inheritance type, so I want it to fetch the subclasses and also eagerly load the downstream Document or Task entity that's associated with them, and be able to execute clauses on the data.

I can only get half way there:

$builder
    ->select('a')
    ->from('Activity', 'a')
    ->leftJoin('ActivityDocument', 'ad', Query\Expr\Join::WITH, 'a.id = ad.id')
    ->leftJoin('ad.document', 'ad_d')
    ->orWhere('ad_d.user = :user')
    ->leftJoin('ActivityTask', 'at', Query\Expr\Join::WITH, 'a.id = at.id')
    ->leftJoin('at.task', 'at_t')
    ->orWhere('at_t.user = :user')
    ->setParameter('user', $user);

In the above I've fudged the joined inheritance association using ->leftJoin() in order to execute the deep WHERE portion, however because we're doing our own join between two entities, the association between Activity and ActivityDocument is lost.

The entities returned by this query are instances of ActivityDocument and ActivityTask; the hydrated subclasses are returned when we SELECT from Activity, and ActivityDocument and ActivityTask are LEFT JOINed automatically by Doctrine because the Activity entity is recognised as using Joined Inheritance, but there's no way to latch onto these generated LEFT JOINs.
https://github.com/doctrine/doctrine2/blob/2.4/lib/Doctrine/ORM/Query/SqlWalker.php#L376

Note that adding "ad", "at" or "at_d" or "at_t" to the select does not solve this.

A workaround for this specific scenario is this:

$builder->select('ad', 'at', 'ad_d', 'at_t')

This fetch ActivityDocument and ActivityTask specifically, plus their associations. Unfortunately because it is across multiple to-level entities, it causes null rows to be returned in the result set.

Effectively this goes the other way, and adds joins from ActivityDocument to Activity in order to provide the correct hydration of ActivityDocument.
https://github.com/doctrine/doctrine2/blob/2.4/lib/Doctrine/ORM/Query/SqlWalker.php#L348

Note that you still cannot use an alias for Activity because the builder was not the one to specify that relation.

What I want to be able to do
Allow me to define the join across the Join Inheritance entities, so I can use the alias for the superclass/subclass in the query builder!

Rather than DDC-16's idea of "casting" to a class, just let me define the join myself. Obviously this is more a "joined class" than a "joined field" , so extra notation may be required.
A painfully ugly example of this syntax could be something like:

$builder->join('Activity->ActivityDocument', 'ad')

This could then establish the Join as some form of JoinAssociation rather than a RangeVariableDeclaration.

The bigger problem is that SqlWalker::_generateClassTableInheritanceJoins doesn't have scope over any of the joins in the query, and thus can't inspect any relations that have been established in the query builder, and use those instead of generating its own.

Unfortunately I don't know the internals of Doctrine to be of any more use.

Why
Joined Inheritance is a powerful feature, but without being able to use associations across the superclass and subclass it actually creates an annoying dead-end in queries.

There is no good workaround for this issue. If you fetch a Join Inheritance entity you can only examine one side of the inheritance without performing another query.






[DDC-3361] Doctrine error while trying to execute a DQL query on PostgreSQL 9.2.x Created: 23/Oct/14  Updated: 31/Mar/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: DQL
Affects Version/s: 2.4.6
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Reynier Perez Mira Assignee: Marco Pivetta
Resolution: Unresolved Votes: 0
Labels: postgresql, typecast
Environment:

CentOS 6.5, PostgreSQL 9.2, Symfony 2.5.5, Doctrine 2.4.6



 Description   

I have this DQL on a repository class:

    public function filterNorm($codigo = null, $anno = null, $term = null, $comite_tecnico = null)
    {
        $qb = $this->getEntityManager()->createQueryBuilder();
        $qb
                ->select('n')
                ->from("AppBundle:Norma", "n");

        if ($codigo != NULL) {
            $qb->where(
                    $qb->expr()->like('n.numero', $qb->expr()->literal('%'.$codigo.'%'))
            );
        }

        if ($anno != NULL) {
            $qb->orWhere(
                    $qb->expr()->like('n.anno', $qb->expr()->literal('%'.(int) $anno.'%'))
            );
        }

        if ($term != NULL) {
            $qb->orWhere(
                    $qb->expr()->like('n.nombre', $qb->expr()->literal('%'.$term.'%'))
            );
        }

        if ($comite_tecnico != NULL) {
            $qb->orWhere(
                    $qb->expr()->like('n.comite_tecnico', $qb->expr()->literal('%'.(int) $comite_tecnico.'%'))
            );
        }

        return $qb->getQuery()->getResult();
    }

And when I try to execute it, leaving the first paramter null, I got this error:

An exception occurred while executing 'SELECT n0_.numero AS numero0, n0_.anno AS anno1, n0_.id AS id2, n0_.nombre AS nombre3, n0_.activo AS activo4, n0_.comite_tecnico_id AS comite_tecnico_id5 FROM nomencladores.norma n0_ WHERE n0_.anno LIKE '%34%' OR n0_.nombre LIKE '%sad%'':

SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: integer ~~ unknown
LINE 1: ...o_id5 FROM nomencladores.norma n0_ WHERE n0_.anno LIKE '%34%...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. 

I think in somewhere Doctrine is failing or not, not so sure, if not what will be the solution around this issue I'm having?



 Comments   
Comment by Marco Pivetta [ 23/Oct/14 ]

First of all: do not hardcode parameters in your DQL, as that represents a possible DQL injection vector.

Is your schema in sync with the ORM mappings? Postresql seems to complain about a missing operator between incompatible types.

Comment by Reynier Perez Mira [ 23/Oct/14 ]

What you mean with "do not hardcode parameters in your DQL"? How should I do this? And yes schema and ORM mappings are good:

Symfony > doctrine:schema:validate
[Mapping] OK - The mapping files are correct.
[Database] OK - The database schema is in sync with the mapping files.

Comment by Marco Pivetta [ 23/Oct/14 ]

What you mean with "do not hardcode parameters in your DQL"? How should I do this?

You wrote:

$qb->where($qb->expr()->like('n.numero', $qb->expr()->literal('%'.$codigo.'%')));

Should be:

$qb->where($qb->expr()->like('n.numero', ':codigo'));
$qb->setParameter('codigo', '%' . $codigo . '%');
Comment by Reynier Perez Mira [ 08/Nov/14 ]

Hi there @ocramius any advice around this issue? Any tip to get ride of this? I have similar queries all over the application I'm working on and still don't know how to deal with this, thanks

Comment by Marco Pivetta [ 08/Nov/14 ]

Seems to be a db-side type mismatch in a comparison, not a D2 bug.

Comment by Reynier Perez Mira [ 08/Nov/14 ]

@ocramius and how I should deal with this? Any idea?

Comment by Felipe Araújo Nunes de Lima [ 31/Mar/15 ]

I think the field 'numero' is an integer and because it cannot be used in a LIKE function.
I'm looking for a function that search for parts of numbers in doctrine, and i have a little idea to do it.





[DDC-3298] Persisting one to one not nullable relational entity Created: 08/Sep/14  Updated: 30/Mar/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.4.4
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Bil Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 1
Labels: onetoone, persist
Environment:

Use with Symfony 2.5



 Description   

When having a not nullable onetoone unidirectional relation and trying to persist the parent entityn sql throws this exception : SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'deliveryMode_id' cannot be null.

Scheme is Shop has a deliveryMode :

class Shop{

...

/**

  • @ORM\OneToOne(targetEntity="acme\Bundle\DeliveryBundle\Entity\DeliveryMode", cascade= {"all"}

    , orphanRemoval=true)

  • @ORM\JoinColumn(nullable=false)
  • @Assert\Valid
    */
    private $deliveryMode;
    ...
    }

When I do a :

$shop=new Shop();
$deliveryMode=new DeliveryMode();
$shop->setDeliveryMode($deliveryMode);
...
$entityManager->persist($shop);
$entityManager->flush();

Then, above exception is thrown

BUT: When I put in on a doctrine transaction, it works perfectly, and it also works when I remove the "not nullable" constraint, deliveryMode is perfectly persisted.

It seems to me there a bug with the order of executing the inserts, the deliveryMode should be inserted, then the shop, I think that is not the case



 Comments   
Comment by webDEVILopers [ 27/Mar/15 ]

Same problem here with the following annotations:

class Bundle
{
    /**
     * @ORM\OneToOne(targetEntity="ParttypeStateNokBlocked", mappedBy="bundle", cascade={"persist"})
     */
    public $parttypeStateNokBlocked;

    /**
     * @param field_type $parttypeStateNokBlocked
     */
    public function setParttypeStateNokBlocked($parttypeStateNokBlocked) {
        $this->parttypeStateNokBlocked = $parttypeStateNokBlocked;
    }
}

class ParttypeStateNokBlocked
{
    /**
     * @ORM\OneToOne(targetEntity="Bundle", inversedBy="parttypeStateNokBlocked")
     * @ORM\JoinColumn(name="bundle_id", referencedColumnName="id")
     */
    public $bundle;

    public function setBundle(\Plusquam\Bundle\ContractBundle\Entity\Bundle $bundle = null)
    {echo "setting bundle";exit;
        $this->bundle = $bundle;

        return $this;
    }
}

Error: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'bundle_id' cannot be null

The setBundle method is not called. I tested the SQL Query for inserting the bundle and it works fine.

Comment by Patrick Laxton [ 30/Mar/15 ]

I guess I'm stupid to ask, but isn't your foreign key not nullable, which you cannot set because you don't have any key right now?
Could you mysqldump your database structure? (Or pgdump, or whatever DBS you're using)

Comment by webDEVILopers [ 30/Mar/15 ]

Here is my setup causing the error in 2.4.7 and 2.5.0-DEV:
https://gist.github.com/webdevilopers/a8b39361d65b7d9d5ca4





[DDC-3639] [GH-1349] Fix #1347 Created: 26/Mar/15  Updated: 27/Mar/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

This issue is created automatically through a Github pull request on behalf of zeroedin-bill:

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

Message:

This PR fixes #1347.



 Comments   
Comment by Doctrine Bot [ 27/Mar/15 ]

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





[DDC-3644] One To Many Relationships do not properly support Orphan Removal Created: 27/Mar/15  Updated: 27/Mar/15

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

Type: New Feature Priority: Major
Reporter: Jarrett Croll Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

After speaking to @guilhermeblanco you assume the following method is unreachable when in fact it is not:

https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php#L39

If an entity currently has a persistent collection in a 1-m relationship and that persistent collection is replaced with a new collection the entities not contained in that new collection should be scheduled for deletion but they are not.






[DDC-1507] State change detection for version incrementation (for optimistic locking) in combination with orphanRemoval Created: 23/Nov/11  Updated: 26/Mar/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.1.4, 2.4.7
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Major
Reporter: Georg Wächter Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 1
Labels: unitofwork, versioned

Issue Links:
Reference
is referenced by DDC-2864 New type of lock: OPTIMISTIC_FORCE_IN... Open
is referenced by DDC-3640 Force version increment via mapped pr... Resolved

 Description   

As i understand the documentation correctly, orphanRemoval associations have the meaning of a "part of" relationship. In the example (http://www.doctrine-project.org/docs/orm/2.0/en/reference/working-with-associations.html#orphan-removal) the adresses are part of the contact.

In my opinion we should reason that the state of the adress consists of the states of all nested contacts. As a consequence we should flag the contact as "dirty" when the adresses change.

This is relevant for optimistic locking scenarios or event handlers. In my application i tried to use optimistic locking for "contacts", which does not work if i don't change anything in the contact but only in the nested addresses.



 Comments   
Comment by Benjamin Eberlei [ 27/Nov/11 ]

This is still only an approvement, you can workaround this and handle is in your domain code.

Comment by Georg Wächter [ 27/Nov/11 ]

Not in all cases. The first problem is that my domain code can't modify the version property, doctrine seems to block any manipulations to it. So i'm not able to increment the variable myself.

The only solution is to implement optimistic locking on my own or to add a dummy persistent boolean field that gets inversed by my domain code .. which would trigger the doctrine implementation for the optimistic locking.

I think it's clear that the second option shouldn't be a choice. If doctrine doesn't handle the overall case exactly it should allow me to increment the version number myself.

Comment by Darien Hager [ 26/Mar/15 ]

Bump: I'm having a similar issue. Essentially I want to force the entity's version to be updated, even if there aren't any other "real" changes to go with it.

One idea for a workaround: Since version fields can only be integers or timestamps, define a "clearly wrong" magic value like "FORCE_INCREMENT". This would allow objects to signal without needing a reference to the EntityManager.

Would folks be open to a pull-request over this?





[DDC-2864] New type of lock: OPTIMISTIC_FORCE_INCREMENT Created: 18/Dec/13  Updated: 26/Mar/15

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

Type: New Feature Priority: Minor
Reporter: Szurovecz János Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Reference
relates to DDC-1507 State change detection for version in... Open
is referenced by DDC-3640 Force version increment via mapped pr... Resolved

 Description   

When optimistick locking is being used, the version field is incremented after the update only if the entity itself has been modified. In Domain-Driven Design another kind of locking mechanism is essential: OPTIMISTIC_FORCE_INCREMENT. It means that the version field is always incremented after an update. The lack of this feaure can be realized when only the aggregate root has a version field and some other parts of the aggregate is being modified.

PESSIMISTIC_FORCE_INCREMENT is also an interesting lock type which might be useful as well.



 Comments   
Comment by Darien Hager [ 26/Mar/15 ]

I'm having this same issue, although I'm not certain a new locking-type is the answer.

Basically, I want to ensure that an entity gets updated with a new version integer/timestamp, whether or not anything "real" has been changed on it. It seems the only workaround is to designate a "junk" property and change that, which isn't particularly elegant.

The problem with a locking-type is that individual entities can't signal that they need incrementing without having a reference to the entity-manager so that they can $em->lock() .





[DDC-3184] Invalid hydration of entities using ManyToOne relation via queryBuilder Created: 23/Jun/14  Updated: 25/Mar/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.4, 2.4.1, 2.4.2, 2.4.3
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Dmitry Korotovsky Assignee: Guilherme Blanco
Resolution: Unresolved Votes: 0
Labels: None

Attachments: File DDC3184Test.php    

 Comments   
Comment by Dmitry Korotovsky [ 23/Jun/14 ]

In master branch all works perfect

Comment by Dmitry Korotovsky [ 23/Jun/14 ]

Marco Pivetta, fix in 2.5 branch will be ported to 2.4 stable version?

Comment by Marco Pivetta [ 23/Jun/14 ]

Dmitry Korotovsky first we'll need to check what commit fixed the issue. Could you git bisect with your test?

Comment by Dmitry Korotovsky [ 23/Jun/14 ]

Yes, i found it: https://github.com/doctrine/doctrine2/commit/38b683838648b549aad0e38ce88c70b6393755b3

Comment by Marco Pivetta [ 23/Jun/14 ]

Assigning to Guilherme Blanco, since he is the author of the fix.





[DDC-3515] [GH-1263] #1223 DDC-3453 - make `EntityManager` constructor `public` Created: 18/Jan/15  Updated: 25/Mar/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM, Tools
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: constructor, entitymanager, setup

Issue Links:
Reference
is referenced by DDC-3453 [GH-1223] Refactored construction of ... Resolved

 Description   

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

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

Message:



 Comments   
Comment by Doctrine Bot [ 18/Jan/15 ]

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

Comment by Doctrine Bot [ 18/Jan/15 ]

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

Comment by Doctrine Bot [ 18/Jan/15 ]

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

Comment by Doctrine Bot [ 24/Jan/15 ]

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





[DDC-1283] Possible issue with PersistentCollection#getDelete/InsertDiff() Created: 21/Jul/11  Updated: 25/Mar/15

Status: Reopened
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.1
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Minor
Reporter: Glen Ainscow Assignee: Guilherme Blanco
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Using the following code, when you go from (1, 2) to (1), (2) is deleted as expected. However, if you go from (1, 2) to (2), (1) and (2) are deleted and (2) is then inserted. Is this the desired behaviour? (i.e. 2 extra queries)

$bracket->getTournamentLocations()->takeSnapshot();

$col = $bracket->getTournamentLocations()->unwrap();

$col->clear();

foreach ($form->getValue('tournamentLocations') as $id) {
    $col->add($em->getReference('Tournaments_Model_TournamentLocation', $id));
}

$bracket->getTournamentLocations()->setDirty(true);


 Comments   
Comment by Benjamin Eberlei [ 26/Jul/11 ]

First, you are using internal API therefore you are on your own anyways.

This is marked as improvment now, the functionality works, it may just be inefficient.

Comment by Guilherme Blanco [ 09/Dec/11 ]

Hi,

I'm marking issue as invalid because you're conceptually wrong.
What you're trying to do is telling that a collection of new entities is holded by a collection of Persistent entities.
The reference internally of PersistentCollection to ArrayCollection means a lot here.

Correct code would be you to regenerate the collection (a new ArrayCollection) and just assign it to setTournamentLocations($newCollection);

Does this explanation is enough for you?

Cheers,

Comment by Glen Ainscow [ 23/Dec/11 ]

Hi Guilherme,

If I do this:

$locations = new ArrayCollection();

foreach ($form->getValue('tournamentLocations') as $id) {
    $locations->add($em->getReference('Tournaments_Model_TournamentLocation', $id));
}

$bracket->setTournamentLocations($locations);

... then all the records are deleted, before adding the new records. This is inefficient and causes extra, unnecessary write operations.

Can't Doctrine perform diffs when persisting the collection, so that only the necessary deletes and inserts are executed?

Comment by Guilherme Blanco [ 13/Jan/12 ]

We could add it, but I don't think it worth the effort.
Main problem with this one is that we use C-level binary comparison to get the diff. That's what you entities/hash pointers are different.
We would have to write our own diff-comparator for both collections, which would probably slowdown the entire Doctrine.

I'd rather consider that it's not possible to be done at the moment, but I need much more investigation for that. This will be something that I'll probably only do when I look at this issue again with a lot of time (which is really hard to happen).

If you have some spare time, feel free to make some attempts.
Just don't forget to enable performance tests in Doctrine Unit Test suite.





[DDC-2290] Infer custom Types from the field for query parameters Created: 08/Feb/13  Updated: 25/Mar/15

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

Type: Improvement Priority: Major
Reporter: Matthieu Napoli Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 4
Labels: None


 Description   

When using a mapping Type that declares convertToDatabaseValue, the method is not always called in queries.

Example:

SELECT ... WHERE entity.field = ?1

(with entity.field being of custom type 'the_mapping_type')

Type::convertToDatabaseValue() is correctly called when using:

$query->setParameter('1', 'foo', 'the_mapping_type');

But it is not called when using:

$query->setParameter('1', 'foo');

which gives a query that returns invalid results.

Like other mapping types in this situation, there is no reason the type is not inferred automatically from the field.

I have written a failing test case in Doctrine\Tests\ORM\Functional\TypeValueSqlTest:

    public function testQueryParameterWithoutType()
    {
        $entity = new CustomTypeUpperCase();
        $entity->lowerCaseString = 'foo';

        $this->_em->persist($entity);
        $this->_em->flush();

        $id = $entity->id;

        $this->_em->clear();

        $query = $this->_em->createQuery('SELECT c.id from Doctrine\Tests\Models\CustomType\CustomTypeUpperCase c where c.lowerCaseString = ?1');
        $query->setParameter('1', 'foo');

        $result = $query->getResult();

        $this->assertCount(1, $result);
        $this->assertEquals($id, $result[0]['id']);
    }


 Comments   
Comment by Matthieu Napoli [ 08/Feb/13 ]

See also http://www.doctrine-project.org/jira/browse/DDC-2224

Comment by Matthieu Napoli [ 08/Feb/13 ]

The test is in this branch: https://github.com/myc-sense/doctrine2/tree/DDC-2290

Comment by Matthieu Napoli [ 29/Oct/13 ]

The organization name has changed so the previous URL is a 404.

Here is the branch containing the failing testcase: https://github.com/myclabs/doctrine2/tree/DDC-2290

Comment by Benjamin Morel [ 28/Jan/14 ]

Any news on this one? Also, I just noticed that it does not cover the original problem I've reported in DDC-2224: I was specifically talking about convertToDatabaseValueSQL() and not convertToDatabaseValue().
My problem is that even when passing the third parameter $type, it does not use the conversion function from convertToDatabaseValueSQL().

Should we reopen DDC-2224?

Comment by Doctrine Bot [ 23/Mar/15 ]

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

Comment by Doctrine Bot [ 25/Mar/15 ]

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

Comment by Doctrine Bot [ 25/Mar/15 ]

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





[DDC-1825] generate entities with traits Created: 18/May/12  Updated: 24/Mar/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.2.2
Fix Version/s: None

Type: Improvement Priority: Major
Reporter: Matthias Breddin Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 7
Labels: None
Environment:

php 5.4.3, symfony2.1-dev
php 5.5.12, symfony 2.5



 Description   

When a trait with included setters and getters is used and generate entities is called, doctrine add another set of getters and setters to the "main" entity where the trait is used.



 Comments   
Comment by Martin Aarhof [ 01/May/14 ]
/**
 * @ORM\Entity
 */
class Product {
    use Traits\Created;

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /**
     * Set name
     *
     * @param string $name
     * @return Attribute
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

}
Trait Created {
    /**
     * @var \DateTime $created
     *
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(type="datetime")
     */
    private $created;

    /**
     * @return \DateTime
     */
    public function getCreated()
    {
        return $this->created;
    }
}

Now when I run php app/console doctrine:generate:entities it copies everything from the trait and into the entity, so the entity now looks like

/**
 * @ORM\Entity
 */
class Product {
    use Traits\Created;

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

    /**
     * Set name
     *
     * @param string $name
     * @return Attribute
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * @var \DateTime $created
     *
     * @Gedmo\Timestampable(on="create")
     * @ORM\Column(type="datetime")
     */
    private $created;

    /**
     * @return \DateTime
     */
    public function getCreated()
    {
        return $this->created;
    }

}

And ofcourse invalidates the entity because it now has two methods of the getCreated and two of private $created

Comment by Wilgert Velinga [ 01/Dec/14 ]

Unfortunately I am also suffering from this bug. Is there anything I can do to help resolve it?

Comment by Ludwig Ruderstaller [ 24/Mar/15 ]

Same here - i think an easy fix would be to introduce an additional parameter, which if set, ignores all traits.





[DDC-3610] [GH-1328] [DDC-3609] Syntax error in class table inheritance join when WITH is used in DQL query Created: 10/Mar/15  Updated: 16/Mar/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

I've added a test case to reproduce this issue. It's a bit contrived, but hopefully gives you enough to go on.



 Comments   
Comment by Doctrine Bot [ 16/Mar/15 ]

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





[DDC-3609] Syntax error in class table inheritance join when WITH is used in DQL query Created: 10/Mar/15  Updated: 16/Mar/15

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

Type: Bug Priority: Major
Reporter: Alex Dean Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

When using WITH on entities that use class table inheritance I'm seeing a syntax error in the generated SQL. Two "ON" statements show up:

INNER JOIN DDCNEWOrder d4_ ON d3_.id = d4_.id ON (d4_.id = d0_.id)

PR: https://github.com/doctrine/doctrine2/pull/1328



 Comments   
Comment by Doctrine Bot [ 16/Mar/15 ]

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





[DDC-2988] Notice: Undefined index: joinColumns in BasicEntityPersister.php Created: 19/Feb/14  Updated: 16/Mar/15

Status: Awaiting Feedback
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.3.5, 2.4.2, 2.4.7
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Dennis Væversted Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 3
Labels: None

Attachments: Text File undefined-joinColumn.patch    
Issue Links:
Duplicate
duplicates DDC-2808 Notice: Undefined index: joinColumns ... Resolved
Reference
is referenced by DDC-3578 [GH-1307] Test for DDC-2988 Open

 Description   

When trying to use findBy on a ManyToMany field i receive the error:

Notice: Undefined index: joinColumns in lib/Doctrine/ORM/Persisters/BasicEntityPersister.php

It seems to be caused internally by the code expecting 'joinColumns' to be directly on the association, however it is found under 'joinTable'.
I have attached a patch that atleast fixes my case, hopefully it can be used to pin-point what the error is.



 Comments   
Comment by Dennis Væversted [ 19/Feb/14 ]

Might be related to this one: http://www.doctrine-project.org/jira/browse/DDC-2808

Comment by Litz Ouille [ 28/May/14 ]

Doctrine ORM 2.4.2 Here.

Here are my annotations
https://gist.github.com/LitzOuille/3cf2e73e169c032147ea

The thing I'm trying to do is
$questionRepository->findBy(array('contacts' => $ids)); // $ids = array(1,2,3, ...)

Comment by Marco Pivetta [ 30/May/14 ]

Calin Pristavu did you validate your mappings?

Comment by Calin Pristavu [ 30/May/14 ]

I failed, sorry.
The error came from the many-to-many condition in the entity.
Sorry for generating confusion, comment deleted !

The many-to-one works just fine !

Comment by Litz Ouille [ 03/Jun/14 ]

A little feedback? Is this a bug? Can it be fixed?
Thanks

Comment by Marco Pivetta [ 03/Jun/14 ]

Litz Ouille that particular repository call cannot work. How are we supposed to find an entity from a list of associated IDs? It would have to be the exact match...

Assuming that API would work as I envision it, it looks like a missing feature.

Dennis Væversted in order to accept a patch, we first need a failing test case demonstrating the failing scenario.

Comment by Litz Ouille [ 03/Jun/14 ]

EDIT: Ok my bad.

I am using findBy(array('id', $arrayIds)) and it is working. I thought I was using on a ManyToOne relationship, but no.

EDIT2: @ocramius In fact I would like to find all questions for which the contacts' list contains at least one id. Something like
SELECT q.*
FROM Question q, QuestionContact qc //qc = jointable
WHERE q.id = qc.question_id
AND qc.contact_id IN ($ids)

EDIT3: Actually when I try to findBy('ManyToMany', $id), it does not work either. I think I will have to use a repository for every query using a ManyToMany relationship.

EDIT4: Ok, so, as said in the original post, findBy does not work with many-to-many.
Notice: Undefined index: joinColumns (BasicEntityPersister.php line 1666)
Dump($this->class->associationMappings[$field]): https://gist.github.com/LitzOuille/51929fdc3eda5576ed31

Comment by Xander ten Boden [ 13/Jun/14 ]

I've got the same issue, also running doctrine 2.4.2:

multiple users can have multiple departments:

/**
 * @ORM\ManyToMany(targetEntity="CartelAuthDepartment", inversedBy="users")
 * @ORM\JoinTable(name="cartel_auth_user_has_cartel_auth_department",
 *		joinColumns={@ORM\JoinColumn(name="cartel_auth_user_id", referencedColumnName="id")},
 *		inverseJoinColumns={@ORM\JoinColumn(name="cartel_auth_department_id", referencedColumnName="id")}
 * )
 */
private $departments;

/**
 * @ORM\ManyToMany(targetEntity="\Cartel\AuthBundle\Entity\CartelAuth\CartelAuthUser", mappedBy="departments")
 */
private $users;

Then I want to find all the users that are within the departments that the current user has:

$aAuthUsers = $oEm->getRepository('CartelAuthBundle:CartelAuth\CartelAuthUser')->findByDepartments($aAuthDepartments);

This results in this error:

Notice: Undefined index: joinColumns in .../vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php line 1665

Comment by Alexander [ 29/Jan/15 ]

I have same problem with doctrine 2.4.7:

Acme\ProjectBundle\Entity\Employee:
  manyToMany:
    projectbag:
      targetEntity: ProjectBag
      mappedBy: bagemployee
Acme\ProjectBundle\Entity\ProjectBag:
  manyToMany:
    bagemployee:
          targetEntity: Employee
          inversedBy: projectbag
          joinTable:
            name: ProjectBag_Employee
            joinColumns:
              ProjectBag_id:
                referencedColumnName: id
            inverseJoinColumns:
              Employee_id:
                referencedColumnName: id

$em->getRepository('AcmeProjectBundle:ProjectBag')->findBy(array('bagemployee'=>$em->getRepository('AcmeProjectBundle:Employee')->find(828)));

Notice: Undefined index: joinColumns in vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php at line 1670

Comment by George Brooks [ 06/Feb/15 ]

What is meant by "Awaiting feedback"?

After encountering the same error as described above I've created a new Symfony project with the sole purpose of reproducing the error. If this would be of use in resolving the issue please let me know. I can make the code available in whatever form would be the most useful.

Comment by Marco Pivetta [ 06/Feb/15 ]

in order to accept a patch, we first need a failing test case demonstrating the failing scenario.

We don't need a symfony project or an example app: we have our own test suite that can be found at https://github.com/doctrine/doctrine2/tree/master/tests

Comment by Carl Boisvert [ 13/Feb/15 ]

I have the same issue. Want to filter on a relationship on the owning side (Because I got an error on the non owning side saying I needed to be on the owning side) and I get the exact same error.

Comment by Ilya Antipenko [ 19/Feb/15 ]

As workaround we can collect IDs and pass it to queryBuilder, like:

    public function findAllSwitcherTypeByComponents($components)
    {
        $ids = [];
        /** @var Component $component */
        foreach ($components as $component) {
            $ids[] = $component->getId();
        }

        $query = $this->createQueryBuilder('component_switcher_type');
        $query
            ->join( 'component_switcher_type.components', 'components', 'WITH', $query->expr()->in('components.id', $ids));

        return $query->getQuery()->getResult();
}
Comment by Marco Pivetta [ 19/Feb/15 ]

Don't code workarounds: provide a test case, so that a patch can be created

Comment by Ilya Antipenko [ 19/Feb/15 ]

I'll this ASAP.

Comment by Ilya Antipenko [ 20/Feb/15 ]

Here is the test: https://github.com/doctrine/doctrine2/pull/1307
Here is the test log on travis-ci: https://travis-ci.org/aivus/doctrine2/builds/51516067

Comment by Doctrine Bot [ 16/Mar/15 ]

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





[DDC-3578] [GH-1307] Test for DDC-2988 Created: 20/Feb/15  Updated: 16/Mar/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Reference
relates to DDC-2988 Notice: Undefined index: joinColumns ... Awaiting Feedback

 Description   

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

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

Message:

This test can be merged only after fix issue DDC-2988

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



 Comments   
Comment by Doctrine Bot [ 16/Mar/15 ]

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





[DDC-3604] [GH-1323] - added isset validation for "inversedBy" Created: 08/Mar/15  Updated: 16/Mar/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:



 Comments   
Comment by Doctrine Bot [ 16/Mar/15 ]

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

Comment by Doctrine Bot [ 16/Mar/15 ]

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





[DDC-3592] [GH-1318] Respect the "unique" property of the join column on the owning side of a... Created: 27/Feb/15  Updated: 16/Mar/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Reference
relates to DDC-1666 orphanRemoval does not work with oneT... Resolved

 Description   

This issue is created automatically through a Github pull request on behalf of ed-at-work:

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

Message:

... One to One association. Coupled with Orphan Removal on the mapped side, this should provide better compatibility for replacing the row without getting duplicate key errors.



 Comments   
Comment by Doctrine Bot [ 16/Mar/15 ]

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

Comment by Doctrine Bot [ 16/Mar/15 ]

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





[DDC-3580] [GH-1308] [DDC-3579] Allow override of inversedBy Created: 20/Feb/15  Updated: 16/Mar/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:



 Comments   
Comment by Doctrine Bot [ 16/Mar/15 ]

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

Comment by Doctrine Bot [ 16/Mar/15 ]

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





[DDC-3584] [GH-1310] Allow symfony 3.0 components Created: 22/Feb/15  Updated: 16/Mar/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

This issue is created automatically through a Github pull request on behalf of nicolas-grekas:

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

Message:

Tests should tell if any deprecated interfaces of Symfony are used. If not, then the bundle is defacto compatible with 3.0



 Comments   
Comment by Doctrine Bot [ 16/Mar/15 ]

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





[DDC-3539] [GH-1284] #1189 DDC-3406 derived identity in proxy must be a proxy Created: 24/Jan/15  Updated: 16/Mar/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Dependency
is required for DDC-3406 Proxy returns string instead of object Open

 Description   

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

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

Message:

This is a horrible hack for #1189.

Not happy with it, this seems like it fixes just the symptom.



 Comments   
Comment by Doctrine Bot [ 24/Jan/15 ]

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

Comment by Doctrine Bot [ 24/Jan/15 ]

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

Comment by Doctrine Bot [ 24/Jan/15 ]

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

Comment by Doctrine Bot [ 25/Jan/15 ]

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

Comment by Doctrine Bot [ 25/Jan/15 ]

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

Comment by Doctrine Bot [ 16/Mar/15 ]

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





[DDC-3618] Refactor PersistentCollection Created: 16/Mar/15  Updated: 16/Mar/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Lazy Loading, ORM
Affects Version/s: 2.5
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Major
Reporter: Varga Bence Assignee: Guilherme Blanco
Resolution: Unresolved Votes: 0
Labels: collection, orm


 Description   

PersistentCollection - a final class - contains all the metadata, used to speed up updates (through $snapshot). This information should be removed from the collection object and stored elsewhere, loosely coupled.

Doctrine2 uses the data mapper pattern (instead of Doctrine1's active record approach). This tells me that the designers see the importance of freedom which comes with loose coupling. Entities don't have to extend fixed base classes, why do collections?

Use case: I would like to use a wrapper around Collection (my current environment requires collections to have a certain functionality). This is possible in theory, but as I do the first step I'm losing all the advantages coming with PersistentColelction. Since it is a final class and logically an interface by itself (see the sniffing in ObjectHydrator#initRelatedCollection) it is impossible to create a wrapper which exposes the same functionality.

A short-term solution would be to extract an interface from PersistentColelction. A long-term one would be to manage the persisted state (currently PersistentCollection#snapshot) elsewhere (accessed through the EntityManager maybe).






[DDC-3413] Types are always ignored when performing a one to many statement Created: 26/Nov/14  Updated: 12/Mar/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Edouard COLE Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: persister


 Description   

BasicEntityPersister#getOneToManyStatement() is building an array named $criteria. This array is built this way:

$criteria[$tableAlias . "." . $targetKeyColumn] = ...;

This means this array is indexed by keys looking like that:

t0.fieldName

But the function BasicEntityPersister#expandParameters() is used in this function, and this function is NOT able to handle SQL field name as keys, but PHP attributes, because it uses BasicEntityPersister#getType() which is doing this:

case (isset($this->class->fieldMappings[$field])):
case (isset($this->class->associationMappings[$field])):

I think the $criteria array should be used to call BasicEntityPersister#getSelectSQL(), but another array should be passed to expandParameters. Here is a potential fix:

$cleanCriteria[$owningAssoc['fieldName']] = $criteria[$tableAlias . "." . $targetKeyColumn] = ...;

And $cleanCriteria should be passed to expandParameters.



 Comments   
Comment by Marco Pivetta [ 27/Nov/14 ]

Edouard COLE I suggest you to open a pull request with a failing test case, otherwise this issue is hard to follow/understand.

Comment by Edouard COLE [ 12/Mar/15 ]

I think this issue is fixed since https://github.com/doctrine/doctrine2/commit/ce446a6f033ca46fc65911e6f40299336ddace74





[DDC-3612] Make SQLFilter#em protected Created: 11/Mar/15  Updated: 11/Mar/15

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

Type: Improvement Priority: Minor
Reporter: Evan Owens Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

SQLFilter#em is private, which can be troublesome when extending SQLFilter. I notice, for example, that the Gedmo SoftDeleteableFilter goes to the trouble of using reflection to get access to SoftDeleteableFilter#em.






[DDC-3605] [GH-1324] load all many to many join columns Created: 08/Mar/15  Updated: 10/Mar/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

the ```$joinColumnElement``` variable is created inside the foreach loop, and used only after it finishes, causing only the last join column to be loaded.



 Comments   
Comment by Doctrine Bot [ 10/Mar/15 ]

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

Comment by Doctrine Bot [ 10/Mar/15 ]

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





[DDC-3603] Readonly columns Created: 06/Mar/15  Updated: 06/Mar/15

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

Type: New Feature Priority: Major
Reporter: Przemyslaw Wrobel Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Sometimes I have a column that is calculated (or have a default value) at the database side. When inserting a new record doctrine issues NULL into such a column that causes problems on some DBMS. I would like to annotate such columns as readonly so that doctrine would skip them in INSERT and UPDATE clauses but still fetch them in SELECT clauses.






[DDC-3602] allow regex in filter option for convert-mapping cli Created: 05/Mar/15  Updated: 05/Mar/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Tools
Affects Version/s: 2.4.7
Fix Version/s: None
Security Level: All

Type: New Feature Priority: Major
Reporter: Jochem Blok Assignee: Steve Müller
Resolution: Unresolved Votes: 0
Labels: cli, convert-mapping, filter


 Description   

It is possible to use the filter option to filter which table is converted. It uses as strpos function of php. Please enable the power of regular expressions.






[DDC-3600] Implement include columns annotation for indexes Created: 05/Mar/15  Updated: 05/Mar/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.4.7
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Jochem Blok Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: annotation, index, mssql, sqlserver
Environment:

Sql Server



 Description   

Sql server has an option to include columns in an index. There is no (optional) annotation for this functionality. http://doctrine-orm.readthedocs.org/en/latest/reference/annotations-reference.html#annref-index



 Comments   
Comment by Marco Pivetta [ 05/Mar/15 ]

Why would you need this sort of feature, when an index already defines the included columns?

Comment by Jochem Blok [ 05/Mar/15 ]

the advantages are described on the MSDN website:

By including nonkey columns, you can create nonclustered indexes that cover more queries. This is because the nonkey columns have the following benefits:
They can be data types not allowed as index key columns.
They are not considered by the Database Engine when calculating the number of index key columns or index key size.





[DDC-3601] @index where annotation not filled with convert-mapping cli Created: 05/Mar/15  Updated: 05/Mar/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.4.7
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Jochem Blok Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: annotation, cli, convert-mapping, index, mssql, sqlserver
Environment:

Sql Server



 Description   

When you use the CLI tool "orm:convert-mapping --from-database xml" the generated XML file does not contain the optional WHERE for the indexes. It look like this is not implemented in de Doctrine\ORM\Tools\Export\Driver\XmlExporter






[DDC-3423] Column Ordering when creating tables using doctrine:schema:update Created: 01/Dec/14  Updated: 05/Mar/15

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

Type: Improvement Priority: Minor
Reporter: Raja Venkataraman Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 3
Labels: None


 Description   

When you have a Base class (annotated with @MappedSuperClass) having some columns, say, createdById, createdDateTime and child entities deriving from the BaseClass, the ordering of the SQL when running doctrine:schema:update looks like

createdById
createdDateTime
id
field1
field2

i.e. the columns of the Base class come up first and then that of the children. It looks odd when you write a SQL to insert into these tables because the default ordering is not what you expect (Which would be derived class columns first and then base class).

I looked into ClassMetadataFactory that adds the fields to the classmetadata and figured if we could move the following
$this->addInheritedFields($class, $parent);
$this->addInheritedRelations($class, $parent);

to after the point where the local fields are added to the classmetadata, this problem is solved.

It might be even better if we have an annotation to specify the Ordering of columns but nevertheless this will help in cases where the base class columns appear after the derived class columns.

Note: Did look into columnDefinition annotation to specify a "AFTER <column>", but that cannot be used during CREATE TABLE, only for ALTER TABLE and that too, its mysql specific.



 Comments   
Comment by Michael Topor-Grabowski [ 05/Mar/15 ]

This would be a great feature. I am using inheritance in the entity classes and have the same problem.
Even if this is not a common taks for ORM, but i simplifies your life





[DDC-3598] Paginator incorrect ordering Created: 03/Mar/15  Updated: 03/Mar/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Tools
Affects Version/s: 2.4.7
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Kris Assignee: Steve Müller
Resolution: Unresolved Votes: 0
Labels: paginator


 Description   

When ordering by multiple fields, with the order by fields not contained in the original select statement the paginator outputs in an incorrect order.
I found the issue is in the LimitSubqueryOutputWalker in the preserveSqlOrdering function. This is the query it generates

SELECT DISTINCT id1, date_added3 FROM (SELECT t0_.description AS description0, t0_.id AS id1, t0_.date AS date2, t0_.date_added AS date_added3 FROM Ticket t0_ INNER JOIN user u1_ ON t0_.assigned_user_id = u1_.id INNER JOIN user u2_ ON t0_.created_user_id = u2_.id WHERE t0_.project_id = ? ORDER BY u2_.first_name DESC, t0_.date_added DESC) dctrn_result ORDER BY date_added3 DESC

So it appears that it ignores any order by field that is not included in the inner select statement.






[DDC-3593] INDEX BY doesnt't work for NEW ArticleDTO Created: 01/Mar/15  Updated: 01/Mar/15

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

Type: Bug Priority: Major
Reporter: Ondřej Vodáček Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

With this query the resulting array is not indexed by id, but from zero

Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
$query = $em->createQuery('SELECT NEW ArticleDTO(a.id, a.title) FROM Article a INDEX BY a.id');
$articles = $query->getResult();





[DDC-3582] Nested embeddables are instantiated with the wrong class Created: 22/Feb/15  Updated: 27/Feb/15

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

Type: Bug Priority: Major
Reporter: Jan Kramer Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Consider the example where an entity contains an embeddable, that itself contains 2 different embeddables. So Entity -> Embeddable 1 -> (Embeddable 2, Embeddable 3). In this case, Embeddable1 will be instantiated as an Embeddable2 for some reason.

Please see https://github.com/jankramer/doctrine2/commit/5e6b02a0fa9a1216b4e4d075061619288af74e7a for a test that demonstrates this and currently fails.

I looked at the code in the ReflectionEmbeddedProperty, and noticed that 'embeddedClass' was recently changed from 'class'. If I change it back, this test passes, but then the ReflectionEmbeddedPropertyTest fails on the scenario for abstract classes. @ocramius, I saw you were the author on that change, could you please take a look? Thanks!



 Comments   
Comment by Jan Kramer [ 22/Feb/15 ]

Closing this as I can't seem to reproduce this issue anymore.

Comment by Jan Kramer [ 24/Feb/15 ]

Now able to reproduce this issue, updated the description.

Comment by Marco Pivetta [ 24/Feb/15 ]

Jan Kramer please send a PR with that diff

Comment by Jan Kramer [ 24/Feb/15 ]

@ocramius See https://github.com/doctrine/doctrine2/pull/1311

Comment by Doctrine Bot [ 27/Feb/15 ]

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

Comment by Doctrine Bot [ 27/Feb/15 ]

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





[DDC-3583] [GH-1309] [DDC-3582] Fix hydration of nested embeddables Created: 22/Feb/15  Updated: 27/Feb/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

The wrong class is chosen when hydrating embeddables that are part of a nested structure. See `DDC3582Test` for a demonstration. The fix is to use `class` instead of `embeddedClass` to instantiate the embeddable in ReflectionEmbeddedProperty.

The test I removed from ReflectionEmbeddedPropertyTest was failing because you cannot instantiate an abstract class (and rightfully so). However, as this would not be possible in practice anyway (you always end up extending the abstract class), I think this test can be removed safely.



 Comments   
Comment by Doctrine Bot [ 22/Feb/15 ]

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

Comment by Doctrine Bot [ 27/Feb/15 ]

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

Comment by Doctrine Bot [ 27/Feb/15 ]

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





[DDC-128] Consider adding EntityManager#link/unlink methods for direct association manipulation Created: 07/Nov/09  Updated: 24/Feb/15

Status: Awaiting Feedback
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.0-ALPHA2
Fix Version/s: 2.x
Security Level: All

Type: New Feature Priority: Major
Reporter: Roman S. Borschel Assignee: Roman S. Borschel
Resolution: Unresolved Votes: 1
Labels: None

Issue Links:
Reference
is referenced by DDC-546 New fetch mode EXTRA_LAZY for collect... Resolved

 Description   

A problem when working with collection-valued associations is that almost all operations except add($obj) require the collection to become initialized in order for the operation to be performed properly. While this is all correct and beautiful OO-wise it may be problematic at times with regards to performance. Hence we might want to consider to provide some convenient methods along the lines of link/unlink (name suggestions?) which allow more direct, less OO collection manipulation. Such methods obviously would bypass the normal object lifecycle and the changes done through these methods will not be reflected in the in-memory objects and collections, unless the user keeps them in-synch himself.



 Comments   
Comment by Benjamin Eberlei [ 11/Dec/09 ]

Questions

  • I suppose link and unlinked entities would then handled by UnitOfwork commit also?
  • Since the collection is not initialized, one does not know upfront if the action will be successful, what happens if:
    • an entity is linked with a collection, although they are already connected.
    • an entity is unlinked from a collection it is not in.

Regarding the naming, i like link/unlink.

Comment by Roman S. Borschel [ 17/Dec/09 ]

What do you mean by "handled by UnitOfWork commit" ? Whether the SQL is "scheduled" or executed immediately? Interesting question.
Scheduling would probably be better but also more difficult.

As far as usage is concerned, I currently imagine it as follows:

// EntityManager#link($sourceObj, $field, $targetObj)
$user = $em->getReference($userId); // $userId probably from request parameters
$address = $em->getReference($addressId); // $addressId probably from request parameters
$em->link($user, 'addresses', $address);

"What happens if: an entity is linked with a collection, although they are already connected."

Probably an SQL error which results in an exception from the driver. Depends on the database constraints though.

"What happens if: an entity is unlinked from a collection it is not in"

Probably nothing, at least not from the SQL side. An exception could be thrown from Doctrine itself if the update affected 0 rows.

Thanks for these initial questions. Thats definitely food for thought. Keep it coming.

Comment by Roman S. Borschel [ 26/Aug/10 ]

Pushed back.





[DDC-2556] Proxy getId() different code generated when using Trait Created: 16/Jul/13  Updated: 23/Feb/15

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

Type: Bug Priority: Minor
Reporter: Eduardo Oliveira Assignee: Marco Pivetta
Resolution: Unresolved Votes: 0
Labels: None


 Description   
class Timezone {
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="smallint", nullable=false, options={"unsigned": true})
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * Get id
     *
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
}

If I replace that code with a Trait with equal code and use it on the entity the proxy will be generated different.

Without trait:

    /**
     * {@inheritDoc}
     */
    public function getId()
    {
       	if ($this->__isInitialized__ === false) {
            return (int)  parent::getId();
        }


       	$this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array());

       	return parent::getId();
    }

With trait:

    /**
     * {@inheritDoc}
     */
    public function getId()
    {

        $this->__initializer__ && $this->__initializer__->__invoke($this, 'getId', array());

        return parent::getId();
    }

And in this code:

$timezone = $this->timezoneRepository->findReadOnly(
    $campaign->getTimezone()->getId()
);

I get:
Doctrine\ORM\ORMException: The identifier id is missing for a query of EB\Core\KernelBundle\Entity\Common\Timezone

$campaign->getTimezone()->getId()
Is returning null.

About the findReadOnly is just a wrapper that will fetch from cache if not there fetch from DB, anyway if I change it to find() exact same problem

My versions of doctrine:

$ php composer.phar show -i | grep doctrine
doctrine/annotations                   v1.1.2             Docblock Annotations Parser
doctrine/cache                         v1.0               Caching library offering an object-oriented API for many cache backends
doctrine/collections                   v1.1               Collections Abstraction library
doctrine/common                        2.4.0-RC4          Common Library for Doctrine projects
doctrine/data-fixtures                 dev-master 6924952 Data Fixtures for all Doctrine Object Managers
doctrine/dbal                          2.4.0-RC2          Database Abstraction Layer
doctrine/doctrine-bundle               v1.2.0             Symfony DoctrineBundle
doctrine/doctrine-fixtures-bundle      dev-master 512fc0f Symfony DoctrineFixturesBundle
doctrine/doctrine-migrations-bundle    dev-master 5fc1167 Symfony DoctrineMigrationsBundle
doctrine/inflector                     v1.0               Common String Manipulations with regard to casing and singular/plural rules.
doctrine/lexer                         v1.0               Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                    dev-master ced3b41 Database Schema migrations using Doctrine DBAL
doctrine/orm                           2.4.0-RC2          Object-Relational-Mapper for PHP
gedmo/doctrine-extensions              v2.3.6             Doctrine2 behavioral extensions
stof/doctrine-extensions-bundle        dev-master 6577f23 Integration of the gedmo/doctrine-extensions with Symfony2


 Comments   
Comment by Marco Pivetta [ 16/Jul/13 ]

Is the problem here the repository or just the trait method?

Can you please clean up the issue to insulate only the affected part? What is `getId` returning on that kind of object?

Comment by Eduardo Oliveira [ 16/Jul/13 ]

Marco I will try to do better, I will try to do make a test case that proves this.

But i can leave here already more info:

  • There is an entity Campaign that have a Timezone (ManyToOne in Campaign side);
  • This entity Campaign is fetch (with lazy in all associations) and serialized and put in cache;
  • This entity Campaign don't have timezone itself, but $campaign->getTimezone()->getId() hit the return (int) parent::getId(); on proxy not making any query to get the timezone, in the case with trait the proxy code is different and it returns null
Comment by Marco Pivetta [ 16/Jul/13 ]

Eduardo Oliveira is the proxy in a detached state when you do this? What happens if (with an existing identifier) you do following?

var_dump($entityManager->getReference('Timezone', 123)->getId());
Comment by Eduardo Oliveira [ 16/Jul/13 ]
var_dump ( $this->timezoneRepository->getEM()->getReference('EBCoreKernelBundle:Common\Timezone', 1)->getId() ); // 1

Marco yes is on detached mode, and I know that, I'm relying on the proxy to get the ID, because I don't want any queries being "issued", so I'm doing like

$campaign = $campaignRepository->findReadOnly(10); // hit cache
$timezoneRepository->findReadOnly($campaign->getTimezone()->getId() /* rely on proxy */); // hit memcache

This just work in the last versions of Doctrine that have lazy getId(), but it looks that for traits something wrong happens on the generation of Proxy.

If on Entity timezone I use the trait but override the getId() everything works perfect again.

Comment by Marco Pivetta [ 16/Jul/13 ]

Eduardo Oliveira does this also happen with 2.3.x? (asking because the proxy generation logic was rewritten for 2.4)

Comment by Eduardo Oliveira [ 16/Jul/13 ]

2.3 the proxy is quite different but the essence of the problem remains:

Proxy with trait (doesn't work, because as far as I know will try to make a query in detach mode):

    public function getId()
    {
        $this->__load();
        return parent::getId();
    }

Proxy without trait (works well):

    public function getId()
    {
        if ($this->__isInitialized__ === false) {
            return (int) $this->_identifier["id"];
        }
        $this->__load();
        return parent::getId();
    }
Comment by Marco Pivetta [ 16/Jul/13 ]

Ok, so at least I now know it's not an issue with the upgrade, but it was also borked before. Thanks for following along till here: I'll work on a patch as soon as I have time.

Comment by Thomas Ploch [ 23/Feb/15 ]

@ocramius

This just got a little bit hotter for us. We moved all our ID related code into a trait that is shared by most our entities. After deploying that we saw a dramatic rise in small id based queries to the database, which is related to this bug here.

We had to revert the changes for now, but I'd be happy to work on a fix if there still is a need.

Regards
Thomas

Comment by Thomas Ploch [ 23/Feb/15 ]

See http://www.doctrine-project.org/jira/browse/DCOM-276





[DDC-3581] DatabaseDriver does not assert nullable on ToOne associationMappings Created: 21/Feb/15  Updated: 21/Feb/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Mapping Drivers, Tools
Affects Version/s: 2.4.7
Fix Version/s: None

Type: Improvement Priority: Minor
Reporter: Ryan Korczykowski Assignee: Marco Pivetta
Resolution: Unresolved Votes: 0
Labels: None


 Description   

I am using the DatabaseDriver/AnnotationExporter to tweak class generation and found that JoinColumn annotations did not contain nullable=false even when the local FK column was not null. This is counter-intuitive since nullable on Column annotations is properly handled.

Here is a simple fix that checks the column of the local column in DatabaseDriver::buildToOneAssociationMappings:

for ($i = 0; $i < count($fkColumns); $i++) {
    $associationMapping['joinColumns'][] = array(
        'name'                 => $fkColumns[$i],
        'referencedColumnName' => $fkForeignColumns[$i],
        //fix here
        'nullable' => !$foreignKey->getLocalTable()->getColumn($fkColumns[$i])->getNotNull()
    );
}

Given that the database defines null / not null on FK columns, the JoinColumn nullable attribute should not be left undefined.






[DDC-3577] Inherited associations are ignored Created: 20/Feb/15  Updated: 20/Feb/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Tools
Affects Version/s: 2.4.6
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Denis Vasilev Assignee: Steve Müller
Resolution: Unresolved Votes: 0
Labels: schematool


 Description   

Could not create schema via SchemaTool for entity, which has inherited accosiation mapping (this mapping is ignored).

ShemaTool.php
private function gatherRelationsSql($class, $table, $schema, &$addedFks, &$blacklistedFks)
{
    foreach ($class->associationMappings as $mapping) {
        if (isset($mapping['inherited'])) {
            continue;
        }
...

I have three entity types:

  • BaseType — mapping mapped-superclass, has association many-to-one, join-column pid
  • SecondType extends BaseType — mapping entity
  • ThirdType extends SecondType — mapping entity

Table for ThirdType not has pid column after created scheme via SchemeTool. Inheritance mapping not using.



 Comments   
Comment by Marco Pivetta [ 20/Feb/15 ]

This should actually be working: you probably need to provide a test case otherwise

Comment by Denis Vasilev [ 20/Feb/15 ]

https://github.com/yethee/doctrine2/commit/d55a8bc71381db1c599da682c4baca0ce39d0d62
Test case for this issue.

$ phpunit --group=DDC-3577
PHPUnit 4.7-g7c1de6a by Sebastian Bergmann and contributors.

Configuration read from D:\Projects\doctrine2\phpunit.xml.dist

F

Time: 1.97 seconds, Memory: 81.75Mb

There was 1 failure:

1) Doctrine\Tests\ORM\Tools\SchemaToolTest::testInheritedAssociationShouldBeSupported
Table "ddc3577_interviews" should has column "user_id".
Failed asserting that false is true.




[DDC-3579] Allow override of inversedBy Created: 20/Feb/15  Updated: 20/Feb/15

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

Type: New Feature Priority: Minor
Reporter: z38 Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: inheritance


 Description   

If an entity inherits a many-to-many relationship it is sometimes desirable to be allowed to override inversedBy. This way bi-directional relationships can exist without code duplication. For examples, check out this and this Stackoverflow question.

The proposed pull-request implements this feature. I'm open to any comments and suggestions. Please just let me know if this feature is opposed to any concepts/practices, I'm not sure whether the feature is needed by anyone else.






[DDC-3575] Paginator's CountOutputWalker keeps the ORDER BY in the subquery for all non-MSSQL platforms Created: 20/Feb/15  Updated: 20/Feb/15

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

Type: Bug Priority: Major
Reporter: John Flatness Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: paginator

Issue Links:
Reference
relates to DDC-3519 [GH-1267] Failing test for an ORDER B... Resolved
relates to DDC-3538 [GH-1283] #1267 - order by broken in ... Resolved

 Description   

The Paginator's CountOutputWalker leaves the ORDER BY clause in the subquery that's executed to get the total count.

The original (and current) version of that code included the following comment:

Note that the ORDER BY clause is not removed. Many SQL implementations (e.g. MySQL) are able to cache subqueries. By keeping the ORDER BY clause intact, the limitSubQuery that will most likely be executed next can be read from the native SQL cache.

My understanding is that MySQL does not, in fact, cache subqueries in the query cache, so cached results are not available between executions of different queries. The current MySQL manual still states that "Queries that are a subquery of an outer query" are not cached.

This pull request was merged in 2013 to address errors with mssql and paginating ordered queries. Midway through the discussion on that issue, it was determined that it would be better to just remove the ORDER BY clause for all platforms, not just MS SQL. However, that decision was reversed when it came time to merge the PR.

Does the comment on that method accurately describe the rationale for retaining the ORDER BY clause for the count query? If so, am I simply wrong about how MySQL operates, or does the comment refer to some other platform that benefits from this pattern?



 Comments   
Comment by Marco Pivetta [ 20/Feb/15 ]

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

This change was reverted because MSSQL is pretty much a niche, and fixing bugs for it is really making things complicated for all the other storages.

Comment by John Flatness [ 20/Feb/15 ]

Thanks for the reply, Marco.

I think this is getting conflated with the other Paginator-related ORDER BY changes and reversions that have happened breaking and fixing the actual sorting behavior. The pull you linked looks like its relating to the LimitSubqueryOutputWalker, not the CountOutputWalker.

The thing I'm talking about is still there, and does specifically address only a MSSQL bug: https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php#L82

The particular part of the discussion on PR #572 I was referring to above is here: https://github.com/doctrine/doctrine2/pull/572#discussion_r3154962

My concern is that the rationale for keeping the ORDER BY intact for all the other platforms (only when running the count query, not the "real" one) is a performance-related one, and that it's a flawed rationale. (Or, at least, that the comment about it is.)





[DDC-3573] DateTime objects casted to string when used in aggregate functions in query results Created: 18/Feb/15  Updated: 18/Feb/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.3.4
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Ameer Antar Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: dbal, mysql, orm, querybuilder
Environment:

MySQL, possibly others



 Description   

Similar to DDC-657: http://www.doctrine-project.org/jira/browse/DDC-657

DateTime objects are converted to strings when selecting them through an aggregate function.

Example:

Update.php Column definition
    /**
     * @var \DateTime
     * @ORM\Column(name="entryDate", type="datetime")
     */
    private $entryDate;
Query Builder
		$qb = $this->getEntityManager()->createQueryBuilder();
		$qb->select('u.code, max(u.entryDate) as updateDate');
		$qb->from('Update', 'u');
		$qb->addGroupBy('u.code');

		var_dump( $qb->getQuery()->getResult() );

The result contains the date/times as strings not DateTime objects as expected. This affects the query builder. I assume it also affects DQL queries.






[DDC-3571] Alter ResultSetMapping on NEW DQL (typeMapping for newObjectMappings) Created: 17/Feb/15  Updated: 17/Feb/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Documentation, DQL, ORM
Affects Version/s: 2.4
Fix Version/s: None
Security Level: All

Type: Documentation Priority: Minor
Reporter: Ignace Assignee: Guilherme Blanco
Resolution: Unresolved Votes: 0
Labels: None


 Description   

In the documentation it says that with the NEW operator only scalars are passed but it is limited to only string? Or is it possible to hint it to return floats and integers aswell?

Currently I hacked this together:

private function getIncomeOutgoingPerMonthQuery($year, &$rsm)
    {
        $rsm = new ResultSetMapping();
        $rsm->addScalarResult('sclr0', 'amount_sum', 'integer');

        return $this->createQueryBuilder('t')
            ->select('NEW AppBundle\ValueObject\Money(SUM(t.amount), t.currency), SUBSTRING(t.date, 6, 2) AS HIDDEN month')
            ->where('SUBSTRING(t.date, 1, 4) = :year')
            ->groupBy('t.currency')
            ->addGroupBy('month')
            ->setParameter('year', (int)$year);
    }





[DDC-3460] SchemaTool create unnecessry work by trying to set foreign keys on MyISAM tables Created: 20/Dec/14  Updated: 16/Feb/15

Status: Awaiting Feedback
Project: Doctrine 2 - ORM
Component/s: Tools
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: flack Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 1
Labels: None


 Description   

When I run SchemaTool::getSchemaFromMetadata, it always adds foreign keys constraints for all association fields (in SchemaTool::gatherRelationJoinColumns). Since I've set the table's engine option to 'MyISAM', this is quite pointless, since they won't get created anyways.

When I run SchemaManager::createSchema, it does not detect any foreign keys, so the SchemaDiff from Comparator will contain a large number of (pointless) ADD CONSTRAINT FK_xxx FOREIGN KEY commands.

For the moment, I work around this by removing them in a ToolEvents::postGenerateSchemaTable listener, but shouldn't SchemaTool be able to detect this situation itself?



 Comments   
Comment by flack [ 16/Feb/15 ]

This says "awaiting feedback" now. Is there any question that I can answer?

Comment by Marco Pivetta [ 16/Feb/15 ]

I think this is a "won't fix", as we don't consider MyISAM as supported.

The "awaiting feedback" flag was mainly because tests are missing.

Comment by Steve Müller [ 16/Feb/15 ]

I think we fixed that already in DBAL 2.5: https://github.com/doctrine/dbal/commit/e95afefab614ecb352791cf09fd5f831d7e5b3be





[DDC-3550] [GH-1293] EntityManager::__cosntruct() as public method Created: 28/Jan/15  Updated: 16/Feb/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:



 Comments   
Comment by Doctrine Bot [ 16/Feb/15 ]

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





[DDC-3259] Second level & UnitOfWork inconsistencies Created: 19/Aug/14  Updated: 16/Feb/15

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

Type: Improvement Priority: Major
Reporter: Asmir Mustafic Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: second-level-cache


 Description   

Hi!

I have a lot of entities with entity associations as keys and I'm trying to use second level cache.

Looking at the method: UnitOfWork::createEntity($className, array $data, &$hints = array())

  • $className: contains the class name
  • $data: contains the raw data (the row coming from the database)

Enabling the second level cache, DefaultQueryCache::get calls the createEntity method passing a $data that contains object entities and some raw data (https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Cache/DefaultQueryCache.php#L155).

I think that DefaultQueryCache should not introduce a variant of $data and should create a compatible version of $data.



 Comments   
Comment by Marco Pivetta [ 19/Aug/14 ]

Asmir Mustafic do you have any example of where this may be happening?

Comment by Asmir Mustafic [ 19/Aug/14 ]

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

This is the same branch of https://github.com/doctrine/doctrine2/pull/1113, plus this commit (https://github.com/goetas/doctrine2/commit/bfbbb9123fd28f7fa053b76895eaa77e00095aa6) that simply involves the second level cache too.
Travis should fail soon.

Comment by Doctrine Bot [ 19/Aug/14 ]

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

Comment by Asmir Mustafic [ 19/Aug/14 ]

Here the failure https://travis-ci.org/doctrine/doctrine2/jobs/32972996#L402

Comment by Doctrine Bot [ 22/Oct/14 ]

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

Comment by Doctrine Bot [ 18/Jan/15 ]

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

Comment by Doctrine Bot [ 24/Jan/15 ]

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

Comment by Doctrine Bot [ 24/Jan/15 ]

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

Comment by Doctrine Bot [ 16/Feb/15 ]

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





[DDC-2879] Persisting collections with Composite Primary Keys composed of 2 Foreign Keys and one metadata field Created: 31/Dec/13  Updated: 16/Feb/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.3.4
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Dylan Johnson Assignee: Marco Pivetta
Resolution: Unresolved Votes: 0
Labels: composite, identity, mapping, orm, postgresql
Environment:

Ubuntu 13.04 and PostgresSQL 9.1.0 on Vagrant Virtual Machine running an application with Symfony2 backend and JavaScript client



 Description   

SYNOPSIS

Bug prevents persisting a collection of entities in a join table with a Composite Primary
Key made up of 2 Foreign Keys and one metadata field. From these mapping instructions:
http://docs.doctrine-project.org/en/latest/tutorials/composite-primary-keys.html#use-case-3-join-table-with-metadata

ISSUE DETAILS

SUCCESS: When FOREIGN KEY 1 is the same across items in a collection to be persisted, and FOREIGN KEY 2 is greater than FOREIGN KEY 2 in any existing PRIMARY KEY, the entity and collection are persisted correctly

    • Example: GPA "add val below" exists and has assessment value
      {"grade_point_average_id":1,"assessment_id":1,"value":4}

      We will try to add a new assessment value where assessment_id > that of any existing assessment value for GPA "add val below"

    • Request Payload:
      {"name":"Add Val Below","courses":[],"assessmentValues":[{"assessment":1,"value":4},{"assessment":3,"value":2}]}
    • Debug Log:
      [2014-01-07 11:48:01] app.INFO: START GRADE_POINT_AVERAGE_REPOSITORY #SAVE [GPA #GET_NAME =ADD VAL BELOW] [] []
      [2014-01-07 11:48:01] app.INFO:   BEGIN OUTPUT FOR GRADE POINT AVERAGE Add Val Below - ASSESSMENT VALUE 1 [] []
      [2014-01-07 11:48:01] app.INFO:         ASSESSMENT_VALUE #GET_GRADE_POINT_AVERAGE #GET_ID: 1 [] []
      [2014-01-07 11:48:01] app.INFO:         GRADE_POINT_AVERAGE #GET_ID: 1 [] []
      [2014-01-07 11:48:01] app.INFO:         ASSESSMENT_VALUE #GET_ASSESSMENT #GET_ID: 1 [] []
      [2014-01-07 11:48:01] app.INFO:         ASSESSMENT_VALUE #GET_VALUE: 4 [] []
      [2014-01-07 11:48:01] app.INFO:         MANAGED? 1 [] []
      [2014-01-07 11:48:01] app.INFO:   END OUTPUT FOR GRADE POINT AVERAGE Add Val Below - ASSESSMENT VALUE 2 [] []
      [2014-01-07 11:48:01] app.INFO:   BEGIN OUTPUT FOR GRADE POINT AVERAGE Add Val Below - ASSESSMENT VALUE 2 [] []
      [2014-01-07 11:48:01] app.INFO:         ASSESSMENT_VALUE #GET_GRADE_POINT_AVERAGE #GET_ID: 1 [] []
      [2014-01-07 11:48:01] app.INFO:         GRADE_POINT_AVERAGE #GET_ID: 1 [] []
      [2014-01-07 11:48:01] app.INFO:         ASSESSMENT_VALUE #GET_ASSESSMENT #GET_ID: 3 [] []
      [2014-01-07 11:48:01] app.INFO:         ASSESSMENT_VALUE #GET_VALUE: 2 [] []
      [2014-01-07 11:48:01] app.INFO:         MANAGED?  [] []
      [2014-01-07 11:48:01] app.INFO:   END OUTPUT FOR GRADE POINT AVERAGE Add Val Below - ASSESSMENT VALUE 3 [] []
      [2014-01-07 11:48:01] app.INFO: END GRADE_POINT_AVERAGE_REPOSITORY #SAVE [GPA #GET_NAME =ADD VAL BELOW] [] []
      [2014-01-07 11:48:01] doctrine.DEBUG: "START TRANSACTION" [] []
      [2014-01-07 11:48:01] doctrine.DEBUG: INSERT INTO gpa_assessment_value (point_value, grade_point_average_id, assessment_id) VALUES (?, ?, ?) {"1":2,"2":"1","3":"3"} []
      [2014-01-07 11:48:01] doctrine.DEBUG: UPDATE gpa_assessment_value SET point_value = ? WHERE grade_point_average_id = ? AND assessment_id = ? [4,1,1] []
      [2014-01-07 11:48:01] doctrine.DEBUG: "COMMIT" [] []

FAILURE: When FOREIGN KEY 1 is the same across items in a collection, and FOREIGN KEY 2 is less than any existing FOREIGN KEY 2, the unit of work tries to INSERT existing entity and does not operate on new entity. The EntityManager thinks it contains() the new entity, but not the old one

    • Example: GPA "add val above" exists and has assessment value
      {"assessment":3,"value":2}

      We will try to add a new assessment value where assessment_id < that of any existing assessment value for GPA "add val above"

    • Request Payload:
      {"name":"Add Val Above","courses":[],"assessmentValues":[{"assessment":1,"value":4},{"assessment":3,"value":2}]}
    • Debug log:
      [2014-01-07 11:47:09] app.INFO: START GRADE_POINT_AVERAGE_REPOSITORY #SAVE [GPA #GET_NAME =ADD VAL ABOVE] [] []
      [2014-01-07 11:47:09] app.INFO:   BEGIN OUTPUT FOR GRADE POINT AVERAGE Add Val Above - ASSESSMENT VALUE 1 [] []
      [2014-01-07 11:47:09] app.INFO:         ASSESSMENT_VALUE #GET_GRADE_POINT_AVERAGE #GET_ID: 2 [] []
      [2014-01-07 11:47:09] app.INFO:         GRADE_POINT_AVERAGE #GET_ID: 2 [] []
      [2014-01-07 11:47:09] app.INFO:         ASSESSMENT_VALUE #GET_ASSESSMENT #GET_ID: 1 [] []
      [2014-01-07 11:47:09] app.INFO:         ASSESSMENT_VALUE #GET_VALUE: 4 [] []
      [2014-01-07 11:47:09] app.INFO:         MANAGED? 1 [] []
      [2014-01-07 11:47:09] app.INFO:   END OUTPUT FOR GRADE POINT AVERAGE Add Val Above - ASSESSMENT VALUE 2 [] []
      [2014-01-07 11:47:09] app.INFO:   BEGIN OUTPUT FOR GRADE POINT AVERAGE Add Val Above - ASSESSMENT VALUE 2 [] []
      [2014-01-07 11:47:09] app.INFO:         ASSESSMENT_VALUE #GET_GRADE_POINT_AVERAGE #GET_ID: 2 [] []
      [2014-01-07 11:47:09] app.INFO:         GRADE_POINT_AVERAGE #GET_ID: 2 [] []
      [2014-01-07 11:47:09] app.INFO:         ASSESSMENT_VALUE #GET_ASSESSMENT #GET_ID: 3 [] []
      [2014-01-07 11:47:09] app.INFO:         ASSESSMENT_VALUE #GET_VALUE: 2 [] []
      [2014-01-07 11:47:09] app.INFO:         MANAGED?  [] []
      [2014-01-07 11:47:09] app.INFO:   END OUTPUT FOR GRADE POINT AVERAGE Add Val Above - ASSESSMENT VALUE 3 [] []
      [2014-01-07 11:47:09] app.INFO: END GRADE_POINT_AVERAGE_REPOSITORY #SAVE [GPA #GET_NAME =ADD VAL ABOVE] [] []
      [2014-01-07 11:47:09] doctrine.DEBUG: "START TRANSACTION" [] []
      [2014-01-07 11:47:09] doctrine.DEBUG: INSERT INTO gpa_assessment_value (point_value, grade_point_average_id, assessment_id) VALUES (?, ?, ?) {"1":2,"2":"2","3":"3"} []
      [2014-01-07 11:47:09] doctrine.DEBUG: "ROLLBACK" [] []
      [2014-01-07 11:47:09] event.DEBUG: Notified event "kernel.exception" to listener "Symfony\Component\Security\Http\Firewall\ExceptionListener::onKernelException". [] []
      [2014-01-07 11:47:09] event.DEBUG: Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelException". [] []
      [2014-01-07 11:47:09] event.DEBUG: Notified event "kernel.exception" to listener "Symfony\Component\HttpKernel\EventListener\ExceptionListener::onKernelException". [] []
      [2014-01-07 11:47:09] request.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\DBALException: "An exception occurred while executing 'INSERT INTO gpa_assessment_value (point_value, grade_point_average_id, assessment_id) VALUES (?, ?, ?)' with params [2, "2", "3"]:
      
      SQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint "gpa_assessment_value_pkey"
      DETAIL:  Key (grade_point_average_id, assessment_id)=(2, 3) already exists." at /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php line 47 {"exception":"[object] (Doctrine\\DBAL\\DBALException: An exception occurred while executing 'INSERT INTO gpa_assessment_value (point_value, grade_point_average_id, assessment_id) VALUES (?, ?, ?)' with params [2, \"2\", \"3\"]:\n\nSQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint \"gpa_assessment_value_pkey\"\nDETAIL:  Key (grade_point_average_id, assessment_id)=(2, 3) already exists. at /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:47, PDOException: SQLSTATE[23505]: Unique violation: 7 ERROR:  duplicate key value violates unique constraint \"gpa_assessment_value_pkey\"\nDETAIL:  Key (grade_point_average_id, assessment_id)=(2, 3) already exists. at /vagrant/vendor/doctrine/dbal/lib/Doctrine/DBAL/Statement.php:138)"} []
         

CODE

migration.sql
CREATE TABLE assessment
(
    id       bigserial NOT NULL,
    scale_id bigint    NOT NULL,
    title    varchar   NOT NULL,
    passing  boolean   NOT NULL,
    rank     int,

    PRIMARY KEY (id)
);

CREATE TABLE assessment_scale
(
    id   bigserial NOT NULL,
    name varchar   NOT NULL,

    PRIMARY KEY (id)
);

-- ...

CREATE TABLE grade_point_average
(
    id                         bigserial       NOT NULL,
    name                       varchar         NOT NULL,
    additional_credit_allowance numeric(4, 2),

    PRIMARY KEY (id)
);

-- ...

CREATE TABLE gpa_assessment_value
(
    grade_point_average_id bigint        NOT NULL,
    assessment_id          bigint        NOT NULL,
    point_value            numeric(4, 2) NOT NULL,

    PRIMARY KEY (assessment_id, grade_point_average_id),
    FOREIGN KEY (assessment_id) REFERENCES assessment,
    FOREIGN KEY (grade_point_average_id) REFERENCES grade_point_average
);
GradePointAverage.php
<?php
namespace LGSConnect\Model;

use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Column;
//...
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use LGSConnect\Util\ConstructorArgs;
use LGSConnect\Model\GradePointAverage\AssessmentValue;
// ...

/**
 * @Entity("LGSConnect\Repository\GradePointAverageRepository")
 */
class GradePointAverage
{
    // GradePointAverage Model (owning side): a tool for evaluating a student's performance 
    // by dividing the total points earned by total credits attempted.

    use ConstructorArgs;

    /**
     * @Id
     * @GeneratedValue
     * @Column(type="bigint")
     *
     * @var int
     */
    private $id;

    // ...

    /**
     * @OneToMany(targetEntity="LGSConnect\Model\GradePointAverage\AssessmentValue", mappedBy="gradePointAverage", cascade="persist")
     *
     * @var Collection
     */
    private $assessmentValues;
    
    // ...

    /**
     * @param array $args
     */
    public function __construct(array $args = [])
    {
        $this->assessmentValues = new ArrayCollection;
        // ...
        $this->handleArgs($args);
    }
    
    // ...
    
    /**
     * @return Collection
     */
    public function getAssessmentValues()
    {
        return $this->assessmentValues;
    }

    /**
     * @param ArrayCollection $assessmentValues
     */
    public function setAssessmentValues(ArrayCollection $assessmentValues)
    {
        $this->assessmentValues = $assessmentValues;
    }

    /**
     * @param AssessmentValue $assessmentValue
     */
    public function addAssessmentValue(AssessmentValue $assessmentValue)
    {
        $this->assessmentValues->add($assessmentValue);
    }

    /**
     * @param AssessmentValue $assessmentValue
     */
    public function removeAssessmentValue(AssessmentValue $assessmentValue)
    {
        $this->assessmentValues->removeElement($assessmentValue);
    }
    
    // ...
}
AssessmentValue.php
<?php
namespace LGSConnect\Model\GradePointAverage;

use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\JoinColumn;
use LGSConnect\Model\GradePointAverage;
use LGSConnect\Model\Assessment;
use LGSConnect\Util\ConstructorArgs;

/**
 * @Entity("LGSConnect\Repository\GradePointAverage\AssessmentValueRepository")
 * @Table("gpa_assessment_value")
 */
class AssessmentValue
{
    // AssessmentValue Model (inverse side): a number of points assigned 
    // to an Assessment by a Grade Point Average

    use ConstructorArgs;

    /**
     * @Id
     * @ManyToOne(targetEntity="LGSConnect\Model\GradePointAverage")
     */
    private $gradePointAverage;

    /**
     * @Id
     * @ManyToOne(targetEntity="LGSConnect\Model\Assessment")
     */
    private $assessment;

    /**
     * @Column("point_value")
     *
     * @var float
     */
    private $value;

    /**
     * @param array $args
     */
    public function __construct(array $args = [])
    {
        $this->handleArgs($args);
    }

    /**
     * @return GradePointAverage
     */
    public function getGradePointAverage()
    {
        return $this->gradePointAverage;
    }

    /**
     * @param GradePointAverage $gradePointAverage
     */
    public function setGradePointAverage(GradePointAverage $gradePointAverage)
    {
        $this->gradePointAverage = $gradePointAverage;
    }

    /**
     * @return Assessment
     */
    public function getAssessment()
    {
        return $this->assessment;
    }

    /**
     * @param Assessment $assessment
     */
    public function setAssessment(Assessment $assessment)
    {
        $this->assessment = $assessment;
    }

    /**
     * @return float
     */
    public function getValue()
    {
        return $this->value;
    }

    /**
     * @param float $value
     */
    public function setValue($value)
    {
        $this->value = $value;
    }

    /**
     * @return AssessmentScale
     */
    public function getAssessmentScale()
    {
        return $this->assessment->getScale();
    }
}
Assessment.php
<?php
namespace LGSConnect\Model;

use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\ManyToOne;
use LGSConnect\Model\Assessment\Scale;
use LGSConnect\Util\ConstructorArgs;

/**
 * @Entity("LGSConnect\Repository\AssessmentRepository")
 */
class Assessment
{
    // Assessment (related, but unmapped): A "grade" assigned to a student 
    // for attending a course section

    use ConstructorArgs;

    /**
     * @Id
     * @GeneratedValue
     * @Column(type="bigint")
     *
     * @var int
     */
    private $id;
    
    // ...

    /**
     * @param array $args
     */
    public function __construct(array $args = [])
    {
        $this->handleArgs($args);
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }
    
    // ...
}
GradePointAverageRepository.php
<?php
namespace LGSConnect\Repository;

use Doctrine\ORM\EntityRepository;
// ...
use LGSConnect\Model\GradePointAverage;

class GradePointAverageRepository extends BaseRepository implements GradePointAverageRepositoryInterface
{
    // ...

    /**
     * @param GradePointAverage $gradePointAverage
     */
    public function save(GradePointAverage $gradePointAverage)
    {
        $this->getEntityManager()->persist($gradePointAverage);
        $this->getEntityManager()->flush();
    }
}
AssessmentValueRepository.php
<?php
namespace LGSConnect\Repository\GradePointAverage;

use Doctrine\ORM\EntityRepository;
use LGSConnect\Model\GradePointAverage\AssessmentValue;

class AssessmentValueRepository extends EntityRepository
{
    /**
     * @param AssessmentValue $assessmentValue
     */
    public function save(AssessmentValue $assessmentValue)
    {
        $this->getEntityManager()->persist($assessmentValue);
        $this->getEntityManager()->flush();
    }
}
GradePointAverageManager.php
<?php
namespace LGSConnect\Manager;

use InvalidArgumentException;
use Symfony\Component\Validator\ValidatorInterface;
use JMS\DiExtraBundle\Annotation\Service;
use JMS\DiExtraBundle\Annotation\InjectParams;
use JMS\SecurityExtraBundle\Annotation\PreAuthorize;
use Knp\Component\Pager\Pagination\PaginationInterface;
use LGSConnect\Repository\GradePointAverageRepository;
use LGSConnect\PaginationFactory\GradePointAveragePaginationFactoryInterface;
use LGSConnect\Model\GradePointAverage;

/**
 * @Service("grade_point_average_manager")
 */
class GradePointAverageManager
{
    /**
     * @var GradePointAverageRepository
     */
    private $gradePointAverageRepository;

    /**
     * @var GradePointAveragePaginationFactoryInterface
     */
    private $gradePointAveragePaginationFactory;

    /**
     * @var ValidatorInterface
     */
    private $validator;

    /**
     * @InjectParams
     *
     * @param GradePointAverageRepository $gradePointAverageRepository
     * @param GradePointAveragePaginationFactoryInterface $gradePointAveragePaginationFactory
     * @param ValidatorInterface $validator
     */
    public function __construct(
        GradePointAverageRepository $gradePointAverageRepository,
        GradePointAveragePaginationFactoryInterface $gradePointAveragePaginationFactory,
        ValidatorInterface $validator
    )
    {
        $this->gradePointAverageRepository = $gradePointAverageRepository;
        $this->gradePointAveragePaginationFactory = $gradePointAveragePaginationFactory;
        $this->validator = $validator;
    }

    /**
     * @PreAuthorize("isAllowedToManageTheGradePointAverage(#gradePointAverage)")
     * @param GradePointAverage $gradePointAverage
     * @throws InvalidArgumentException
     */
    public function save(GradePointAverage $gradePointAverage)
    {
        $violationList = $this->validator->validate($gradePointAverage);
        if ($violationList->count()) {
            throw new InvalidArgumentException;
        }

        $this->gradePointAverageRepository->save($gradePointAverage);
    }
}
GradePointAverageController.php
<?php
namespace LGSConnect\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Doctrine\Common\Collections\ArrayCollection;
use FOS\RestBundle\View\View;
use JMS\DiExtraBundle\Annotation\Service;
use JMS\DiExtraBundle\Annotation\InjectParams;
use JMS\SecurityExtraBundle\Annotation\PreAuthorize;
use Knp\Component\Pager\Pagination\PaginationInterface;
use LGSConnect\Manager\GradePointAverageManager;
use LGSConnect\Model\GradePointAverage;
use LGSConnect\Model\GradePointAverage\AssessmentValue;

/**
 * @Service("grade_point_average_controller", parent="lgs.controller.abstract")
 * @Route("/gpa", service="grade_point_average_controller")
 */
class GradePointAverageController extends BaseController
{
    /**
     * @var GradePointAverageManager
     */
    private $gradePointAverageManager;

    private $logger;

    /**
     * @InjectParams
     *
     * @param GradePointAverageManager $gradePointAverageManager
     * @param LoggerInterface $logger
     */
    public function __construct(GradePointAverageManager $gradePointAverageManager, LoggerInterface $logger)
    {
        $this->gradePointAverageManager = $gradePointAverageManager;
        $this->logger = $logger;
    }
    
    // ...

    /**
     * @Route("/{id}", name="gpa.edit", requirements={"id" = "\d+"})
     * @Method("PUT")
     *
     * @param Request $request
     * @param GradePointAverage $gpa
     * @return View
     */
    public function editAction(Request $request, GradePointAverage $gpa)
    {
        $form = $this->formFactory->createNamed(null, 'gpa', $gpa, [
            'method' => 'PUT',
        ]);
        $form->handleRequest($request);

        foreach ($gpa->getAssessmentValues() as $av) {
            $this->logger->info('GPA ID PREVALIDATE IN CONTROLLER:'.$gpa->getId());
            $this->logger->info('PREVALIDATE IN CONTROLLER ASSESSMENT VAL ASSESSMENT ID:'.$av->getAssessment()->getId());
            $this->logger->info('PREVALIDATE IN CONTROLLER ASSESSMENT VAL POINTS:'.$av->getValue());
        }

        /*
        // try reversing the order of the collection to see if that helps
        $assessmentVals = $gpa->getAssessmentValues()->toArray();
        $reversed = array_reverse($assessmentVals);
        $reversedColl = new ArrayCollection($reversed);
        $gpa->setAssessmentValues($reversedColl);
        */

        if ($form->isValid()) {
            foreach ($gpa->getAssessmentValues() as $av) {
                $this->logger->info('GPA ID PRESAVE IN CONTROLLER:'.$gpa->getId());
                $this->logger->info('PRESAVE IN CONTROLLER ASSESSMENT VAL ASSESSMENT ID:'.$av->getAssessment()->getId());
                $this->logger->info('PRESAVE IN CONTROLLER ASSESSMENT VAL POINTS:'.$av->getValue());
            }
            $this->gradePointAverageManager->save($gpa);

            return new View($gpa, 204);
        }

        return new View($form);
    }

    // ...
}
GradePointAverageType.php
<?php
namespace LGSConnect\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use JMS\DiExtraBundle\Annotation\FormType;

/**
 * @FormType
 */
class GradePointAverageType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('name')
            ->add('courses', 'entity', [
                'class' => 'Model:Course',
                'multiple' => true
            ])
            ->add('assessmentValues', 'collection', [
                'type' => 'gpa_assessment_value',
                'allow_add' => true,
                'by_reference' => false,
            ])
        ;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'gpa';
    }
}
AssessmentValueType.php
<?php
namespace LGSConnect\Form\Type\GradePointAverage;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use JMS\DiExtraBundle\Annotation\FormType;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

/**
 * @FormType("gpa_assessment_value")
 */
class AssessmentValueType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('assessment', 'entity', [
                'class' => 'Model:Assessment',
            ])
            ->add('value', 'number', [
                'precision' => 2,
            ])
        ;
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults([
            'data_class' => 'LGSConnect\Model\GradePointAverage\AssessmentValue',
        ]);
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'gpa_assessment_value';
    }
}


 Comments   
Comment by Valentin Nazarov [ 23/Jan/15 ]

Any update on this issue? We've got same problem in our project (PostgreSQL 9.4, Doctrine 2.4.7)

Comment by Marco Pivetta [ 24/Jan/15 ]

Removed the "feedback required" flag.

Valentin Nazarov if there is no ticket update, well... then there is no actual update.

Somewhat related to https://github.com/doctrine/doctrine2/pull/1113

I suggest getting your hands dirty and fixing it yourself if it affects you.

Comment by Doctrine Bot [ 24/Jan/15 ]

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

Comment by Doctrine Bot [ 24/Jan/15 ]

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

Comment by Doctrine Bot [ 16/Feb/15 ]

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





[DDC-3391] RFC Allow adding extra metadata attributes Created: 13/Nov/14  Updated: 15/Feb/15

Status: Awaiting Feedback
Project: Doctrine 2 - ORM
Component/s: Mapping Drivers
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Minor
Reporter: Gonzalo Vilaseca Assignee: Marco Pivetta
Resolution: Unresolved Votes: 1
Labels: drivers, metadata


 Description   

What I'd like to propose is a way of having custom metadata in ClassMetadata.

So the current problem is this: I want to add custom tags to doctrine metadata files, and then get this tags on a loadClassMetadata listener in order to modify the mapping.
Currently the only workaround is parsing this custom tags in the loadClassMetadata listener, going through all the files again.

I was thinking of having a new 'extra' array field in ClassMetadata, every time a driver parses a configuration, throw a new event with the read configuration (being xml, yaml...etc.). A custom listener will parse it looking for the custom tags and return an array that will be added to the 'extra' array field in ClassMetadata.

Then, on the loadClassMetadata listener we retrieve this 'extra' configuration information, and modify the mapping as we want.

Does this make sense?



 Comments   
Comment by Gonzalo Vilaseca [ 14/Nov/14 ]

Ideally instead of the 'extra' array field, it would be nice to easily extend Metadata class so that the new values are filled in the new extended Metadata class.

Comment by Christophe Coevoet [ 14/Nov/14 ]

This would be even worse. If the recommended way for extensions is to extend the Doctrine Metadata object to add their field, it means you can only use 1 extension at a time (because you cannot use the extended class of both extensions at the same time for the same object).
This is why it is much better for other libraries to store their own metadata in their own object instead of trying to put it inside the Doctrine ones.

I'm not even sure putting custom tags inside the Doctrine mapping file is the best solution. It may be better to use a separate metadata file for the mapping of the other library (just like you use a different mapping file for the Symfony validation mapping even if it applies to the same class than the Doctrine mapping for instance)

Comment by Gonzalo Vilaseca [ 14/Nov/14 ]

You're right regarding the metadata.

As for the separate files, validation in Symfony is not doctrine specific, that's why it's in a separate file. If you have a look at some doctrine extensions like ``Prezent translable`` or ``Doctrine2 behavioral extensions``, the natural location for the custom tags are the Doctrine mapping files as they are specific to doctrine, by looking at just one file you see the whole picture.

Yes, you could have your own mapping files, but then you would need to do some Symfony magic to be able to load them, and this is what would be nice to avoid.

I think of it as a way to easily extend doctrine mapping capabilities, in a 'plugin' way.

I'm currently working on a i18n bundle for Symfony, the tags I add in doctrine mapping files create associations between entities and their translations: I've had to create quite a few compiler passes for my current project to work as desired, and I see no way of abstracting this in a general way, it will need to be application specific. If I could hook into the Doctrine workflow and get those tags to populate my metadata class, that would be great, simple and reusable.

Comment by Gonzalo Vilaseca [ 19/Nov/14 ]

I've come out with another use case:
I need some custom metadata when the repository is instantiated, AFAIK there is no way of doing this right now, or is there?

Comment by Marco Pivetta [ 19/Nov/14 ]

You'd use a different metadata factory for that, specific to your use-case.
Mixing ORM mappings with the rest will just cause more coupling between the ORM and the userland use-case.

Comment by Michał Dobaczewski [ 15/Feb/15 ]

As Gonzalo Vilaseca metioned without ability to set custom metadata attributes in ClassMetadata there is no proper way to obtain custom metadata in repository class. For example popular DoctrineDxtensions written by Gediminas Morkevicius obtain custom metadata by looping throught event subscribers (https://github.com/Atlantic18/DoctrineExtensions/blob/master/lib/Gedmo/Sortable/Entity/Repository/SortableRepository.php). By the way, shame that Doctrine has no API for extensions.





[DDC-3565] "Missing value for primary key" error using JoinColumns Created: 11/Feb/15  Updated: 11/Feb/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.4, 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Minor
Reporter: Arran Walker Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: orm


 Description   

With a ManyToOne relationship to a composite foreign key and using JoinColumns, I get this error during hydration of the Branch entity when it has no associated primary Contact:

Missing value for primary key user on Contact

If there is an associated Contact, it works as expected.

I think it's related to this error on StackOverflow.

User.php
<?php

/**
 * @Entity()
 */
class User
{
    /**
     * @Id @Column(type="integer") @GeneratedValue
     */
    protected $id;

    /**
     * @Column(type="string")
     */
    protected $name;

    public function __construct($name)
    {
        $this->name = $name;
    }

    public function getId()
    {
        return $this->id;
    }
}
Branch.php
<?php

use Doctrine\Common\Collections\ArrayCollection;

/**
 * @Entity
 */
class Branch
{
    /**
     * @Id @Column(type="integer") @GeneratedValue
     */
    protected $id;

    /**
     * ORM\OneToMany(targetEntity="Contact", mappedBy="Branch", cascade={"persist", "remove"}, indexBy="user")
     */
    protected $contacts;

    /**
     * @ManyToOne(targetEntity="Contact")
     * @JoinColumns(
     *   @JoinColumn(name="primary_contact_user_id", referencedColumnName="user_id"),
     *   @JoinColumn(name="id", referencedColumnName="branch_id")
     * )
     */
    protected $primaryContact;

    public function __construct()
    {
        $this->contacts = new ArrayCollection();
    }

    public function addUserAsContact(User $user)
    {
        if (!$this->contacts[$user->getId()]) {
            $this->contacts[$user->getId()] = new Contact($this, $user);
        }

        return $this->contacts[$user->getId()];
    }

    public function setUserAsPrimaryContact(User $user)
    {
        $this->primaryContact = $this->addUserAsContact($user);
    }
}
Branch.php
<?php


/**
 * @Entity
 */
class Contact
{
    /**
     * @Id()
     * @ManyToOne(targetEntity="Branch")
     * @JoinColumn(name="branch_id", referencedColumnName="id", nullable=false)
     */
    protected $branch;

    /**
     * @Id()
     * @ManyToOne(targetEntity="User")
     * @JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
     */
    protected $user;

    public function __construct(Branch $branch, User $user)
    {
        $this->branch = $branch;
        $this->user   = $user;
    }

    public function getUser()
    {
        return $this->user;
    }
}





[DDC-3480] ORM\Embeddable does not create ManyToOne column in the database Created: 09/Jan/15  Updated: 09/Feb/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: Git Master
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Tomas Voslar Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 1
Labels: None

Issue Links:
Reference
relates to DDC-3556 [GH-1297] [DDC-3480] Docs: Embeddable... Resolved

 Description   

Following Embeddable

/**
 * @ORM\Embeddable
 */
class Address
{
    /**
     * @ORM\ManyToOne(targetEntity="Country")
     */
    protected $country;

won't save country attribute into the database table, other simple attributes (like type="text") saved normally.

    /**
     * @ORM\Embedded(class="LuciniLucini\Adsender\CommonBundle\Entity\Address")
     */
    private $address;


 Comments   
Comment by Marco Pivetta [ 09/Jan/15 ]

The issue seems incomplete to me: what exactly is the failure? Can you make an example?

Comment by Tomas Voslar [ 09/Jan/15 ]

Okay, I am sorry. I have main entity which includes Embeddable entity (Address), this address entity contains country attribute with ManyToOne relation, but this country is not being saved into the database table, other attributes like street (string) are being saved normally.

Comment by Tomas Voslar [ 09/Jan/15 ]

Basically it creates main entity with all fields from embeddable except country which is ManyToOne.

Comment by Marco Pivetta [ 09/Jan/15 ]

Ah, now I get it (I was probably misreading it). We don't support associations from embeddables right now: please check the test suite, but they really don't provide this functionality right now.

Comment by Tomas Voslar [ 09/Jan/15 ]

And is there any chance it will be supported in the near future? Or it's not possible?

Comment by Marco Pivetta [ 09/Jan/15 ]

It will probably not implemented for now, as embeddables (in our vision) are fitting the use-case of ValueObjects. ValueObjects are (usually) supposed to be containing serializable data, and an entity reference is not serializable data.

Comment by Tomas Voslar [ 09/Jan/15 ]

Okay, understood. So it's not good idea to use embeddables for Address entity for example, with this country as relation to another table, right? It seemed to me like best case. Thank you for the support anyway.

Comment by Marco Pivetta [ 09/Jan/15 ]

So it's not good idea to use embeddables for Address entity for example, with this country as relation to another table, right?

I'd rather just save the country identifier in the embeddable instead.

Comment by Tomas Voslar [ 09/Jan/15 ]

So you mean, instead of ManyToOne, save just id=integer (so no relation with entity)?

Comment by Marco Pivetta [ 09/Jan/15 ]

Correct: simple scalar or serializable types

Comment by Tomas Voslar [ 09/Jan/15 ]

https://github.com/doctrine/doctrine2/blob/400acad53355f24137e18d5cd55ccf6ff828cfbe/tests/Doctrine/Tests/ORM/Functional/ValueObjectsTest.php

Line 121 method testDqlOnEmbeddedObjectsField, guess I am wrong, but it seems there should be support for embeddable with relations though.

Comment by Yavin [ 11/Jan/15 ]

Hi,
if is is not supported i think an exception should be thrown when someone use association in embedded class. Now it is just silently ommited.

I found code where embedded metadata is added:
https://github.com/doctrine/doctrine2/blob/573153669c11a6f69201513831d3b8ce5e111d25/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php#L3200

Comment by Eugene Dounar [ 02/Feb/15 ]

It will probably not implemented for now, as embeddables (in our vision) are fitting the use-case of ValueObjects. ValueObjects are (usually) supposed to be containing serializable data, and an entity reference is not serializable data.

This should be explicitly stated in the documentation.

Comment by Marco Pivetta [ 02/Feb/15 ]

Eugene Dounar please send a PR to the documentation with the wording you prefer.

Comment by Eugene Dounar [ 09/Feb/15 ]

Marco Pivetta http://www.doctrine-project.org/jira/browse/DDC-3556





[DDC-3563] Wrong metadata output. One-To-Many, Bidirectional Created: 08/Feb/15  Updated: 08/Feb/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Tools
Affects Version/s: 2.4.7
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Jason Schilling Assignee: Steve Müller
Resolution: Unresolved Votes: 1
Labels: None

Attachments: Zip Archive Data.zip    

 Description   

During observe the metadata in a One-To-Many association I've noticed that, the inversedBy value is NULL but in the annotation its assigned to something like $images (look example). I think its wrong because the EntityGenerator dont get it and dont generate the add..., remove... and get...s Method stubs or the __constructor assignment to ArrayCollections.






[DDC-3562]  Make two different join request with different join condition with Doctrine ORM Created: 06/Feb/15  Updated: 06/Feb/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: 2.4.7
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Colin Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Doctrine2 symfony integration
PHP 5.5.2
MySQL 5.5.41
Linux
doctrine/annotations v1.2.3
doctrine/cache v1.4.0
doctrine/collections v1.2
doctrine/common v2.4.2
doctrine/dbal v2.5.1
doctrine/doctrine-bundle v1.3.0
doctrine/doctrine-cache-bundle v1.0.1
doctrine/inflector v1.0.1
doctrine/lexer v1.0.1
doctrine/orm v2.4.7



 Description   

I want to make two requests on an object and join a one to many relation using doctrine ORM. The first request has different condition on the joined object.
The first request should join one object, and the second one two, but both return one object when run with the same EntityManager context.

The test entity

    /**
     * TreeNode
     *
     * @ORM\Table(name="treeNode")
     */
    class TreeNode {
    	/**
    	* @var integer
    	*
    	* @ORM\Id
    	* @ORM\Column(name="id", type="integer")
    	* @ORM\GeneratedValue(strategy="AUTO")
    	*/
    	private $id;
    
    	/**
    	* @var string
    	*
    	* @ORM\Column(name="name", type="string", length=50)
    	*/
    	private $name;
    
    	/**
    	* @var \Doctrine\Common\Collections\Collection
    	*
    	* @ORM\JoinColumn(name="subdirs", nullable=true)
    	* @ORM\OneToMany(targetEntity="TestBundle\Entity\TreeNode", mappedBy="parent", cascade={"persist"})
    	*/
    	private $subdirs;
    
    	/**
    	* @var TestBundle\Entity\TreeNode
    	*
    	* @ORM\JoinColumn(name="parent", nullable=true)
    	* @ORM\ManyToOne(targetEntity="TestBundle\Entity\TreeNode", inversedBy="subdirs")
    	*/
    	private $parent;
    }

Adding some test data

    $parent = new TreeNode();
    $parent->setName('Parent');
    $parent->setParent(null);
    
    $child1 = new TreeNode();
    $child1->setName('Child1');
    $child1->setParent($parent);
    
    $child2 = new TreeNode();
    $child2->setName('Child2');
    $child2->setParent($parent);

Run the queries

    $repo = $em->getRepository('TestBundle:TreeNode');

    $qb = $repo->createQueryBuilder('t');
    $qb->innerJoin('t.subdirs', 'subnode')
    		->addSelect('subnode')
    		->where('t.name = :parentName')
    		->setParameter('childName', 'Child1')
    		->andWhere('subnode.name = :childName')
    		->setParameter('parentName', 'Parent');
    
    $result = $qb->getQuery()->getOneOrNullResult();
    var_dump($result->getSubdirs()->count()); // Gives 1, ok 
    
    
    // Get parent parent + all childs
    $qb = $repo->createQueryBuilder('t');
    $qb->innerJoin('t.subdirs', 'subnode')
    		->addSelect('subnode')
    		->where('t.name = :parentName')
    		->setParameter('parentName', 'Parent');
    $result = $qb->getQuery()->getOneOrNullResult();
    var_dump($result->getSubdirs()->count()); // Gives 1, should have been 2 !
  • The second request only returns one "subdir" object, while it should have been two.
  • If I run the second request without the first one, I get the two results, as expected. Inverting the request makes the second one return two results instead of one.
  • The correct SQL requests are run by this code, only the returned result is wrong.
  • Running `$em->clear()` between the two statements works, but I don't want to untrack my other entities.





[DDC-3558] Sequence name generation for identity strategy Created: 04/Feb/15  Updated: 05/Feb/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: Mapping Drivers, ORM
Affects Version/s: Git Master
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Gemorroj Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: generator-strategy, identity, metadata, sequence

Attachments: PNG File Захват-1.png    

 Description   

In version 2.5 added support sequence with the strategy of identity.
But I cannot get the correct name of the sequence with the strategy of identity. With the strategy sequence produces the correct name. It is taken from the configuration sequenceName. Strategy identity name sequence will not be taken from the configuration, and is always generated is automatically (which is not working properly in my case).

see: https://github.com/doctrine/doctrine2/blob/4c68a38bd6b7d590dbfa90b2bb116129381935ce/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php#L632
the title sequence is generated automatically.

https://github.com/doctrine/doctrine2/blob/4c68a38bd6b7d590dbfa90b2bb116129381935ce/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php#L662
and in this case, it first checks its own configuration.



 Comments   
Comment by Gemorroj [ 05/Feb/15 ]

Any comments plz..?

Comment by Marco Pivetta [ 05/Feb/15 ]

Gemorroj consider writing a test case with your problem/example: I can't understand the issue as it is currently written down.

A code example is also fine.

Comment by Gemorroj [ 05/Feb/15 ]

If you use the strategy SEQUENCE, the doctrine calls the sequence specified in the configuration. And inserts a record in the database with the specified ID.
If you are using the IDENTITY strategy, doctrine inserts a record without an ID. And after a record is inserted, causes sequence (https://github.com/doctrine/dbal/blob/8cbfefe03ff2d1a2246dfb6e98b84e4b36622e6f/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php#L148) to learn the value of id.
But, with the IDENTITY strategy, doctrine does not know how actually called a sequence.

Comment by Marco Pivetta [ 05/Feb/15 ]

Yes, when using the IDENTITY strategy, the sequence name is not used: https://github.com/doctrine/doctrine2/blob/4c68a38bd6b7d590dbfa90b2bb116129381935ce/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php#L626-L657

That's expected behavior: what are you expecting?

Comment by Gemorroj [ 05/Feb/15 ]

If doctrine determines that the database uses the sequence, then I expect the setup sequence doctrine is taken from the configuration.
https://github.com/doctrine/doctrine2/blob/4c68a38bd6b7d590dbfa90b2bb116129381935ce/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php#L636-L638
The generated name sequence wrong for me.

Comment by Marco Pivetta [ 05/Feb/15 ]

You should rather just use the SEQUENCE strategy.

Otherwise, provide a functional test case and eventually propose a fix.





[DDC-3319] Get the converted value in convertToDatabaseValueSQL() Created: 23/Sep/14  Updated: 01/Feb/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor
Reporter: Benjamin Morel Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 1
Labels: mapping


 Description   

I have a use case where it would be useful to get the value being converted in the convertToDatabaseValueSQL() method, not just in convertToDatabaseValue().

Take the following mapping for a Geometry type:

    public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        return $value->asBinary();
    }

    public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
    {
        return sprintf('ST_GeomFromWkb(%s, %s)', $sqlExpr, 4326);
    }

In GIS-enabled databases, ST_GeomFromWkb() takes two parameters: the WKB binary representation of the geometry, and an integer representing the SRID (coordinate system) of the geometry, in this example the hardcoded value 4326.

I would be nice to have access to the value being converted in the convertToDatabaseValueSQL() as well, to be able to get the SRID from the geometry object itself, and replace the above code with something like:

    public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform, $value)
    {
        return sprintf('ST_GeomFromWkb(%s, %s)', $sqlExpr, $value->srid());
    }

I don't think there is currently a technical way to do this (please correct me if I'm wrong).

Could we find a BC way to pass the value being converted to the convertToDatabaseValueSQL() method to add support for this use case?



 Comments   
Comment by Michael Lucas [ 25/Jan/15 ]

The use case which you described above would be a great addition to the convertToDatabaseValueSQL() or in the convertToDatabaseValue() be able to return an array of values which could be used in the convertToDatabaseValueSQL().

    public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        return array('geometry' => $value->asBinary(), 'srid'=>$value->getSRID());
    }

    public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
    {
        return sprintf('ST_GeomFromWkb(%s, %s)', ':geometry', ':srid');
    }
Comment by Benjamin Morel [ 25/Jan/15 ]

Michael Lucas It's an interesting idea, it would work as well, although I think it might be much more complicated to implement!

Comment by Paolo Agostinetto [ 01/Feb/15 ]

It there a workaround for this? I'm probably going to use a native query.

My use case is pretty common among Postgres full-text users: I need to insert a record
using the ts_vector() function with both parameters, eg: ts_vector('english', 'This is a test'),
and both parameters has to be passed on record creation.





[DDC-3548] [GH-1291] Conversion to PHP 5.4's short array syntax Created: 28/Jan/15  Updated: 28/Jan/15

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

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

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

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

Message:

Now that the minimum PHP version is 5.4, it would be good to encourage the use of the short array syntax `[]`.
Converting the existing codebase to this syntax will promote this good practice and encourage everyone to follow it.

I have converted the codebase with [a tool](https://gist.github.com/BenMorel/6994483) I wrote for personal projects:

find doctrine2 -type f -name '*.php' -exec php short-array-syntax-converter.php {} \;

The number of changes is quite large, but I'm confident that nothing is broken, and the passing tests confirm this.



 Comments   
Comment by Doctrine Bot [ 28/Jan/15 ]

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

Comment by Doctrine Bot [ 28/Jan/15 ]

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





[DDC-2093] Doctrine Criteria does not support sorting by relationed field Created: 20/Oct/12  Updated: 28/Jan/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: Git Master
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Major
Reporter: Bogdan Yurov Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   
// Here I call Criteria filter
public function getWalletsActive() {
	$criteria = Criteria::create()
		->where(Criteria::expr()->eq("isRemoved", "0"))
		->orderBy(array("currency.id" => "ASC"));
	return $this-&