Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[2.2] [Form] Added form type "entity_identifier" (#1946) #1951

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

Closed
wants to merge 8 commits into from
Prev Previous commit
[Form] OneEntityToIdTransformer, fixing problems with QueryBuilder type
  • Loading branch information
Gregwar committed Oct 17, 2011
commit fc400f54c7e50b80b245cf88e4d707fd92cba2ac
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OneEntityToIdTransformer implements DataTransformerInterface
public function __construct(EntityManager $em, $class, $property, $queryBuilder)
{
if (null !== $queryBuilder && ! $queryBuilder instanceof \Closure) {
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder or \Closure');
throw new UnexpectedTypeException($queryBuilder, '\Closure');
}

if (null === $class) {
Expand Down Expand Up @@ -84,10 +84,8 @@ public function reverseTransform($data)
$repository = $em->getRepository($this->class);

if ($qb = $this->queryBuilder) {
// If a closure was passed, call id with the repository and the id
if ($qb instanceof \Closure) {
$qb = $qb($repository, $data);
}
// Call the closure with the repository and the id
$qb = $qb($repository, $data);

try {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use getOneOrNullResult?

$result = $qb->getQuery()->getSingleResult();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not make sense in the case where a QueryBuilder is passed directly as it does not receive the data at all

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah sorry, looking at the constructor, the queryBuilder property is always a closure (the naming is bad then) which means that the previous check is useless and that a check is missing to be sure you receive a query builder

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.