-
Notifications
You must be signed in to change notification settings - Fork 73
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
Repository service #150
Comments
You need to create the repository class (see https://github.com/floriansemm/SolrBundle#repositories) and then include it via the annotation inside your entity (see https://github.com/floriansemm/SolrBundle#setting-custom-repository-class-with-repository-option) It's basically like the normal doctrine repositories except that you write solr queries instead of using the querybuilder or writing dql. |
But is there a way to use it as a service? |
The repository afaik not. Because a repository is different from a service in Symfony. A repository is a extension of an entity, which you can access directly from the entity repository. A service is (in basic sense) more like a helper that you can include in your controllers or services that does stuff you always have to do anyway (like initialize the client, create the query, set the hydration mode, set standard filters/sorting etc.) You can create a service and inject More infos on how to create a service you can find in the Symfony documentation |
I digged a bit into the code and I see the instantiation of the entity is important for the Repository and other services but it might be avoided as far it is only used to read the annotations in \FS\SolrBundle\Doctrine\Mapper\MetaInformationFactory::loadInformation. What do you think? Update removing the params from MyEntity::__construct() initiated the service with that config I posted |
Oh, I didn't see the edit in your first posting. Can you post your constructor of your service? |
You mean the Entity?
|
@gadelkareem to fix your issue you can set default-constructor parameters:
But your are right. It is a good idea to remove the entity dependency from the repository-class. |
Thank you! is it possible to introduce this improvement any soon? |
I am working on it |
the lastest release includes some refactorings which solves your issue |
Thank you! would the repository service config I posted earlier still work?
|
Yes. I have tested locally with a similar configuration: <service class="FS\SolrBundle\Repository\Repository" id="test_repo">
<factory service="solr.client" method="getRepository" />
<argument>Acme\DemoBundle\Entity\Post</argument>
</service> |
Worked Thank you! |
I just got the same error while using findBy(). The error is in |
Can you explain how do you create a repository service? I could not find it in the docs..
I tried:
I get an error
The text was updated successfully, but these errors were encountered: