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

Allow to findBy/findOneBy directly by given object #70

Open
clementtalleu opened this issue Jul 24, 2024 · 9 comments
Open

Allow to findBy/findOneBy directly by given object #70

clementtalleu opened this issue Jul 24, 2024 · 9 comments

Comments

@clementtalleu
Copy link
Owner

$repository->findBy(['user' => $user]);

@mehdibo
Copy link

mehdibo commented Aug 21, 2024

Just taking a look at your project out of curiosity, why do you have multiple ways of fetching an object?

$user = $objectManager->find(User::class, 1);

$user = $objectManager->getRepository(User::class)->find(1);

@mehdibo
Copy link

mehdibo commented Aug 21, 2024

Also, if you can include more details on the issues you opened I'd be happy to help in my spare time

@clementtalleu
Copy link
Owner Author

@mehdibo The main idea is to imitate and respect the interface of the Doctrine's ObjectManager :

https://github.com/webmozart/doctrine-common/blob/master/lib/Doctrine/Common/Persistence/ObjectManager.php

So, ideally, you could replace Doctrine's EntityManager with the one provided here without changing the way the application works.

However, the best practice is still to inject the repository to retrieve its objects.

@clementtalleu
Copy link
Owner Author

For this issue: currently, to retrieve a resource via its nested object, you need to provide the nested object's ID.

$repository->findOneBy(['user' => $user->id]);

What I want to do is to allow to use it this way

$repository->findOneBy(['user' => $user]);

@mehdibo
Copy link

mehdibo commented Aug 22, 2024

Ah I see, I don't know if RedisOM is supposed to replace instead of go along with Doctrine but I understand your point.

I'd be happy to give it a try this weekend if you didn't already start on it

@clementtalleu
Copy link
Owner Author

No, the plan is not to replace Doctrine, but to be able to use the 2 object mappers interchangeably as needed.

@mehdibo
Copy link

mehdibo commented Aug 22, 2024

Got it, let me know if I can start on it

@mehdibo
Copy link

mehdibo commented Aug 23, 2024

I am currently playing around with the library and trying to implement what you said earlier, would the appropriate approach be

- Check if the related object has an index and use it for the lookup
- If no index is present use the id

Or is there a better way?
I will try to submit a PR this weekend

Nvm why even bother if we can just use the id

@clementtalleu
Copy link
Owner Author

Yes, I think the easiest way is to check if the search criterion is a property that corresponds to an object and if so, retrieve its identifier/index to replace the search parameters.

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

2 participants