-
-
Notifications
You must be signed in to change notification settings - Fork 83
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
Custom persister logic? #695
Comments
Hi Basically, what I'd do would be something like this: abstract class LegacyObjectFactory extends ObjectFactory
{
public function __construct(
private LegacyPersister $legacyPersister
){}
public function initialize(): static
{
return $this->afterInstatiate(
function(object $data): void {$this->legacyPersister->save($data)}
);
}
}
in the future, we may offer an extension point dedicated for this, but there's still work to do before that |
Got a similar problem which would be resolved by this. I am using a When creating fixtues now:
A Custom persister-logic would help here too. Or is there another way to avoid this behavior? |
Hi @sirpilan maybe you can change your listener and not override when a value already exists? 😅 I'm not sure what would be the benefits of a custom persister in your case? Maybe the best option would be to be able to disable doctrine's listeners from the factories 🤔 A previous attempt exists, but the PR was never finished (and, by the way, it should now target branch |
Well, I need the user at the entity i create explicitly here:
A custom persister would give me a tool to bypass the persister without changing my production code. The potential soultion above is technically code I only need so the fixtures for my tests can work, which I'd like to rather not do :D Simply: I want the fixtures to be in the database exactly as I defined them in my tests - regardless of any doctrine listeners etc. EDIT:
This solution is "ok" in my book :D |
I'd like to use Foundry for a legacy code base where objects are not persisted through Doctrine ORM, but other means.
Currently, my factories for such legacy model objects call
$this->withoutPersisting()
in theirinitialize()
method. All clients using these factories callcreate()
or similar and then have to take care of persisting the objects (when necessary) themselves.Is there a standard way or hook that I could use to centralize custom persistence code in the factories?
The text was updated successfully, but these errors were encountered: