Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9097013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:00:22+00:00 2026-06-17T00:00:22+00:00

I want to create a form select field which looks like this: <select> <option

  • 0

I want to create a form select field which looks like this:

<select>
<option value="product.product_id">product_details.detail_name</option>
etc...
</select>

The value is not the problem, the problem is with the label.

I have a product entity and a productDetails entity which contains translated data about a product.

So, in my form type class, in the buildForm method, I have this:

    $builder->add('product', 'entity', array(
        'class' => 'MyBundle:Product',
        'property' => 'details.detail_name',
        'query_builder' => function(EntityRepository $er) {
            return $er->createQueryBuilder('p')
                ->select('p, pd')
                ->join('p.details', 'pd')
                ->where('pd.language_id = :lang')
                ->setParameter('lang', 'en');
        }));

I want the property to be the details.detail_name.

I tried different values for this property value. Like ‘details.detail_name’, ‘pd.detail_name’ and ‘p.details.detail_name’.

But it seems to be impossible to get the property to display the detail name.

When I use to above mentioned code, I get this error:

Neither property "detail_name" nor method "getDetailName()" nor method "isDetailName()" exists in class "Doctrine\ORM\PersistentCollection"

This getDetailName() method does exist in the ProductDetails entity, and I have checked the entities and they all seem to be okay. Also, they work just fine when I use these entities outside the form.

I also tried to execute the resulting query directly on my database, and it gives me the expected results. The detail_name are in the right language.

So, can somebody help me on how to make the select choice list I want, with a joined query?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T00:00:23+00:00Added an answer on June 17, 2026 at 12:00 am

    I finally managed to get this working. Below, I’m showing how I’m doing this, in case someone else has the same problem.

    I am now using a custom form type.

    And in the setDefaultOptions, I am calling a repository method, which returns an array with “product_id” => “detail_name”.

    class ProductChoiceType extends AbstractType
    {
        private $repository;
    
        public function __construct(EntityRepository $repository)
        {
            $this->repository = $repository;
        }
    
        public function setDefaultOptions(OptionsResolverInterface $resolver)
        {
            $resolver->setDefaults(array(
                    'choices' => $this->repository->findAllProductsForForm('nl', true)
                ));
        }
    
        public function getParent()
        {
            return 'choice';
        }
    
        public function getName()
        {
            return 'product_choice';
        }
    }
    

    In the $this->repository->findAllProductsForForm method, I am using a query and a foreach loop to make the array suitable for the choice list.

    Then, I had to register the repository and this type in my services.xml file:

    <service id="mybundle.repository.product"
             factory-service="doctrine.orm.default_entity_manager"
             factory-method="getRepository"
             class="MyBundle\Repository\ProductRepository" >
        <argument>MyBundle:Product</argument> <!-- not sure why I need this, but it wouldn't work without it -->
    </service>
    
    <service id="mybundle.xxx.form.product_choice_type" class="Mybundle\Form\Type\ProductChoiceType">
        <argument type="service" id="mybundle.repository.product" />
        <tag name="form.type" alias="product_choice" />
    </service>
    

    And then, in the root form type (I think it’s called that) I use the ‘product_choice’ as a form type.

    I’m not sure if this the best way to do this, but at least it works.

    Now I only need to figure out how to pass on the current language of the user on to the repository, but that’s a problem for later.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

now, whenever I create a model form which has a FK field, a select
I want to create a query which takes field parameters through a form. For
I want to create a form which has a text entry box where a
I want to create a form in which if the User presses Enter the
I have a form which contains a checkbox field. On page load I want
I want to create a form using an unordered list ul must have only
i want to create a form that has two submit buttons, but each one
I have a database table named Categories . I want to create a form
I want to create a registration form for dealers in my drupal website.Can any
I want to create an input form that will take the input text and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.