Closed NeuralClone closed 2 weeks ago
I took another look at the afterPersist
function signature and it appears the callable no longer accepts an array of attributes:
That seems to contradict the documentation:
https://github.com/zenstruck/foundry/blob/2.x/docs/index.rst#events--hooks
Is this no longer possible?
Hi @NeuralClone
thanks for reporting this. This is a bug in 2.x, let me fix this
Thank you for such a prompt response! It's a bit of a relief that this is a bug and not an intended change.
I figured out a workaround to get everything functional again in case it was intended. But I'm glad I won't have to use it long-term.
curiosity question: using afterInstantiate()
insteadof afterPersist()
is not a choice for you?
It's a good question. Doing it that way is my preference and I've actually been using that approach with other entities.
I ran into a cascade on persist issue with a third party entity that's already configured. It ended up being easier to persist the main object, and then conditionally create and add a different entity to its collection using the extra attribute.
My workaround for this bug was to move the afterPersist() code directly to the tests that need it and therefore not use events at all in the factory in question.
There's probably a better way to do this, but I haven't been able to find the time to properly dig into Foundry's capabilities to address it.
maybe you could give a try in foundry 2, handling of the cascading stuff has been revamped. And if some problems still occurs in that area, we'll try to fix them
Upgrading to v2.0 is definitely as good a time as any for me to re-examine this. My current approach has felt kind of like a hack since I implemented it. So I'll definitely be giving it another look now that so much has been revamped.
I really appreciate all the work that's gone into Foundry. Aside from this one issue when upgrading, using it has been incredibly smooth.
thanks for the kind words!
don't hesitate to post a new issue (with a reproducer :pray: ) if you see other problems with cascading stuff
Yes, cascade is complex and since I never use it in my projects, I admit, I'm flying dark when working on it in foundry.
I've been upgrading my project to use Foundry v2.0. Everything has gone relatively smoothly except updating an event in one of my factory classes. I suspect the problem is on my end and not a bug, but I'm not sure what the problem is.
I'm using Foundry's default bundle configuration.
In a test I create an object as follows:
In 1.x, I did this:
And for 2.x, I currently have this:
The latter causes an error in 2.x:
PHPStan gives the following error:
I've gone over the documentation and upgrade guide to see what I might be doing wrong. I've attempted to debug the issue and that's only muddied things further.
I feel like I'm missing something obvious. What would be the correct way to achieve the above in 2.x?
Thank you!