Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with automatically disabling doctrine id generator #110

Closed

Conversation

Toflar
Copy link

@Toflar Toflar commented Nov 14, 2018

So here's a failing test case for the problem described in #68.

I'll try it again in other words though:

Disabling the id generator automatically when loading fixtures is really super handy. It's always needed and really comfortable. I can just simply specify something like this and my id is not autogenerated even though I have an autogenerator registered for production:

App\Entity\Group:
    group_1:
        id: 44b178b5-ea58-44bf-857f-eb8ce4df1280

Now here's where it gets a bit tricky: If you have related entities with cascade: persist (which is very common I guess), disabling the id generator happens too late for some of the entities.
Imagine this:

App\Entity\Group:
    group_1:
        id: 44b178b5-ea58-44bf-857f-eb8ce4df1280

App\Entity\User:
    user_1:
        id: b3c52f50-992f-44fd-bc71-95acc1eef687
        group: "@group_1"

The way the fixture loader works is it persists every object one after the other. So it will persist group_1 first and only then user_1. Now if you do not have cascade: persist configured, it works just fine. However, if you configured cascade: persist the id for user_1 is generated during ->persist($group1) already.

So handling this in the ObjectManagerPersister does not work. Disabling the UUID generation has to be done before any of the objects is being persisted.
So either we need a special loader (which I don't really like because loading is actually not affected) or we have to have a new interface a Processor can implement that is called before the persister is asked to persist any object.

@Toflar Toflar changed the title Added failing test case Issue with automatically disabling doctrine id generator Nov 14, 2018
@@ -183,7 +204,8 @@ public function provideEntities()
$dummy->id = 300;

return $dummy;
})()
})(),
true
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have re-added here because otherwise that test does not make sense there. Not sure why it was removed because it was present in the original PR: #68

@Toflar
Copy link
Author

Toflar commented Nov 14, 2018

BTW: For people encountering the same issue. You can temporarily fix it by changing the order of your fixture objects. In my example it would work if I defined user_1 before group_1.

@theofidry
Copy link
Owner

@Toflar is this issue still present with #135?

@Toflar
Copy link
Author

Toflar commented Jul 31, 2020

Sorry Théo but this was so long ago, I can't remember and I must have long fixed it otherwise. I don't even remember which project that was :D

@videni
Copy link

videni commented Nov 16, 2020

@@Toflar, this issue still exists

@theofidry
Copy link
Owner

Closed by #198

@theofidry theofidry closed this Dec 21, 2021
@Toflar Toflar deleted the fix-disabling-doctrine-id-generator branch December 21, 2021 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants