Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
Using a Custom Query for the Entities in Doctrine - Symfony Form

I have two tables one is users like this

id _ username _ firstname _ lastname

and the other one is users_test

id _ user_id _ name

I'm trying in Symfony Form (UserTestType) to make a Custom Query to get the id from the first Entitiy (UsersType) and insert the id as a Value. my code is like this:

$builder->add('user_id', EntityType::class, array(
    'class' => 'UserBundle:Users',
    'query_builder' => function (EntityRepository $er) {
        return $er->createQueryBuilder('u')
            ->orderBy('u.id', 'ASC');
    },
    'choice_label' => 'firstname',
    'choice_value' => 'id',
));

when i reload the page it says: Could not load type "Symfony\Component\Form\Extension\Core\Type\EntityType"

note: I'v used Symfony\Component\Form\Extension\Core\Type\EntityType;

I hope someone could help me to find my Problem.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I just tried it out and you probally copy&paste the TextType from user/first/lastname and just changed the last part of the Namespace, which lead you to the namespace where TextType and many other Types are lying. (I did the exact same mistake and lost 2 minutes of my life)

For EntityType and DoctrineType, you need to use following namespace:

use Symfony\Bridge\Doctrine\Form\Type\EntityType;

Also if you didn't do it (I know you wrote you use it, but just in case), you should also use your User Entity Class like:

use UserBundle\Entity\Users;

(or using the Singular form User, which I would recommend so you have no struggling with singular/plural)

I also remember reading somewhere that it is recommended to use the FQCN via ::class so you could think changing:

'class' => 'UserBundle:Users',

to

'class' => Users::class,

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!