Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-586

Repo does not find "unflushed" object

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0
    • Fix Version/s: None
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      The problem is this:

      $bar = new \entity\content\ContentTag();
      $bar->setName('bar');
      $em->persist($bar);

      $existingTag = $em->getRepository('entity\content\ContentTag')->findOneByName('bar');

      Seeing as in EntityRepository "find()" queries the Unit of Work first, and "findBy()" goes directly to the persister, only remotely stored objects will be found. Now if I want a tag object to attach related tags, it would have to query by name to see if an object already exist, BUT it wont find one as the UoW has not been committed, resulting in a new one being created, ultimately resulting in a PDO error on the unique name constraint.

      This can be "solved" by inserting a flush, but it is impossible to know whether a flush is required, without knowledge of what comes next. I.e. for one part to know it has to flush, it has to know another wants to fetch an object you just created.

      This causes an unacceptable amount of coupling.

      Somehow the repo will have to be able execute DQL against the objects in the UoW. This does not have to be full support (straight away), but it should fail (throw an exception) if the possibility exists that the UoW contains items that are excluded (e.g. the operation is not supported and the UoW still contains items).

      For right now, this means the EntityManager should throw an exception if DQL is executed on the type when the UoW is not empty. Until the time that the EntityManager can query the UoW using DQL. The alternative would be to "flush" before every operation that goes to the database for data.

        Activity

        John Kleijn created issue -
        Roman S. Borschel made changes -
        Field Original Value New Value
        Fix Version/s 2.0 [ 10021 ]
        Roman S. Borschel made changes -
        Affects Version/s 2.0 [ 10021 ]
        Fix Version/s 2.0 [ 10021 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 11358 ] jira-feedback [ 13851 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 13851 ] jira-feedback2 [ 15715 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 15715 ] jira-feedback3 [ 17972 ]

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            John Kleijn
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: