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

Multiple entity managers #342

Open
silvandre95 opened this issue Dec 31, 2024 · 9 comments
Open

Multiple entity managers #342

silvandre95 opened this issue Dec 31, 2024 · 9 comments

Comments

@silvandre95
Copy link

Hello, I'm currently working with multiple entity managers and when I extend EntityRepository on my ResetPasswordRequestRepository, I get this error:

image

I know that when extending from EntityRepository we cannot rely on autowire, is this bundle prepared to work with multiple entity managers?

@bocharsky-bw
Copy link
Member

I personally have never tried this bundle with multiple entity managers, but I think it should work well. The error is from your code, right? I mean, this ResetPasswordRequestRepository file is inside the src/ folder where you can modify it as you wish. Just take a look at the working repository class in that App/Repository/Tenant/ folder, most probably you need to tweak that constructor method.

In short, just compare ResetPasswordRequestRepository's construct() with any other working repo construct(), I suppose they are different and you need to do some changes.

@silvandre95
Copy link
Author

It is exactly like the other repositories, this is the only one I get the error. This is how I have the repo.

image

I believe the issue lies on the autowire of the ResetPasswordRequestRepositoryInterface on some files like ResetPasswordHelper.php. According to the multiple entity manager documentation, when we extend EntityRepository, we should not use autowire. But I need to extend EntityRepository for all, otherwise I can't work with multiple tenants.

@bocharsky-bw
Copy link
Member

According to the multiple entity manager documentation, when we extend EntityRepository, we should not use autowire

If so, then it's a problem because as I see the repo is injected in ResetPasswordHelper at least. Will the entity manager injection instead of the repo directly fix the problem? Do you see any other possible (better) solutions for this?

@silvandre95
Copy link
Author

Yes, it can be a solution, but it has to be configurable, we have to be able to configure the entity manager we want otherwise it will always get the default one.

@bocharsky-bw
Copy link
Member

Thanks for confirming. In this case, it seems this bundle is not ready to work with multiple entity managers. If you have any ideas on how to fix it - please, feel free to create a PR

@kbond
Copy link
Contributor

kbond commented Jan 6, 2025

I'll look into this. Should be possible but the bundle could be coded in a way that doesn't allow it. Basically, it should be using the manager registry to fetch repositories by entity.

@kbond
Copy link
Contributor

kbond commented Jan 6, 2025

@silvandre95 first thing: you're repository isn't a service. That's what's causing the error. Can you have it extend ServiceEntityManager like shown here: https://github.com/SymfonyCasts/reset-password-bundle/blob/main/tests/Fixtures/App/src/Repository/ResetPasswordRequestRepository.php (you'll need to override the constructor like in this file but with your entity class)

@silvandre95
Copy link
Author

@kbond if I extend the ServiceEntityRepository, I'll never be able to use this repo with my multi tenant implementation.

image

@kbond
Copy link
Contributor

kbond commented Jan 6, 2025

Ahh, I misunderstood your multi-entity manager usage.

I think what you'll need to do is create your own ResetPasswordRequestRepositoryInterface service (that doesn't extend EntityRepository) and implement it for use with your multi-tenant application logic. Then configure it via symfonycasts_reset_password.request_password_repository.

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

No branches or pull requests

3 participants