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

[DoctrineParamConverter] Allow usage of custom method instead of find/findOneBy #153

Closed
Gregoire-M opened this Issue Aug 13, 2012 · 7 comments

Comments

Projects
None yet
5 participants
@Gregoire-M
Copy link
Contributor

Gregoire-M commented Aug 13, 2012

Hello,

I think it would be useful to allow users to customize the method used by DoctrineParamConverter when it retrieves entities.

I have a case where the DoctrineParamConverter retrieves a blog post entity (using the findOneBy() method), but I also need to retrieve the related comments, tags and other entities. So instead of doing a new query per relation, I'd like to ask to the DoctrineParamConverter to call an custom method that retrieves all my entities in 1 query, using left joins.

Here's an usage example:

<?php
/**
 * @Route("/blog/{id}")
 * @ParamConverter("post", class="SensioBlogBundle:Post", options={"method" = "findOneByIdWithLeftJoins"})
 */
public function showAction(Post $post)
{
}
@henrikbjorn

This comment has been minimized.

Copy link
Contributor

henrikbjorn commented Aug 13, 2012

You can create your own ParamConverter specially for your Entity.

@Gregoire-M

This comment has been minimized.

Copy link
Contributor

Gregoire-M commented Aug 13, 2012

Good idea! I'll do that.
But it could be useful as a built-in behavior in my opinion.

@henrikbjorn

This comment has been minimized.

Copy link
Contributor

henrikbjorn commented Aug 13, 2012

@Gregoire-M the problem with adding it as an option is the endless options we would need to add to support every single use case.

@fabpot

This comment has been minimized.

Copy link
Member

fabpot commented Aug 13, 2012

I agree with you @henrikbjorn, but this one looks useful, especially because it allows you to easily optimize the number of requests you make to the database (and right now, we only have 3 different options).

fabpot added a commit that referenced this issue Oct 4, 2012

merged branch Gregoire-M/ticket_153 (PR #154)
This PR was squashed before being merged into the master branch (closes #154).

Commits
-------

437296d [ParamConverter] added repository_method option to the DoctrineParamConverter

Discussion
----------

[ParamConverter] added repository_method option to the DoctrineParamConverter

[ParamConverter] added possibility to specify the repository method to use for DoctrineParamConverter, using the "repository_method" option

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #153
Todo: -
License of the code: MIT
Documentation PR: -

---------------------------------------------------------------------------

by schmittjoh at 2012-09-15T10:13:11Z

ping @fabpot

This looks pretty useful if you'd like to optimize which relations get loaded depending on the action.
@gimler

This comment has been minimized.

Copy link

gimler commented Oct 10, 2012

@fabpot can you merge this also into the 2.1 branch please? So it has no BC Break and is very useful.

@fabpot

This comment has been minimized.

Copy link
Member

fabpot commented Oct 10, 2012

This is a new feature and as such is done in master.

@jrobeson

This comment has been minimized.

Copy link

jrobeson commented Feb 23, 2013

@Gregoire-M : does the merged PR solve your request? if so can you close this?

@Gregoire-M Gregoire-M closed this Feb 23, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment