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 8373971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:48:53+00:00 2026-06-09T14:48:53+00:00

I am new to the Symfony2 query builder, here is what I do: $builder

  • 0

I am new to the Symfony2 query builder, here is what I do:

    $builder
        ->add('access', 'entity', array(
            'label' => 'Behörigheter',
            'multiple' => true,   // Multiple selection allowed
            'expanded' => true,   // Render as checkboxes
            'property' => 'name', // Assuming that the entity has a "name" property
            'class'    => 'BizTV\ContainerManagementBundle\Entity\Container',
            'query_builder' => function(\Doctrine\ORM\EntityRepository $er) use ($company) {
                $qb = $er->createQueryBuilder('a');
                $qb->where('a.containerType IN (:containers)', 'a.company = :company');
                $qb->setParameters( array('containers' => array(1,2,3,4), 'company' => $company) );

                return $qb;
            }
        ));     

It works fine except I want to order my entities by containerType (which is a relational field, FK).

When I add this line:

$qb->orderBy('a.containerType', 'ASC');

I get Error: Invalid PathExpression. Must be a StateFieldPathExpression.

So what is this – I can use the relation field containerType in my where clause but not in my sort clause? Or am I missing something else?

  • 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-09T14:48:54+00:00Added an answer on June 9, 2026 at 2:48 pm
    'query_builder' => function(\Doctrine\ORM\EntityRepository $er) use ($company) {
          $qb = $er->createQueryBuilder('a');
          $qb->innerJoin('a.containerType', 'ct');
          $qb->where('a.containerType IN (:containers)', 'a.company = :company');
          $qb->orderBy('ct.id', 'ASC'); // Or the field you want from containerType
          $qb->setParameters( array('containers' => array(1,2,3,4), 'company' => $company));
    
          return $qb;
    }
    

    You can’t use containerType with sort clause because this an entity in relation with the current !
    The query builder don’t know the field to use (even containerType represents the id of the entity !).
    So you need to join the entity and sort by its field manually !

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

Sidebar

Related Questions

I'm new in symfony2.I created a repository class when I created an entity class
You know that in Symfony2 a new entity can be defined as in the
I'm new in symfony2 , I don't know how to write a below query
I am trying to add a new query to my app and I'm stuck
This is my form public function buildForm(FormBuilder $builder, array $options) { $builder ->add('nombreBD','text', array(
New to Symfony2. I followed several tutorials to install & configure Sonata with FOSUser
I've been using Symfony for a long time but I'm new to Symfony2. After
I have a strange kind of problem. I'm totally new to symfony2 so forgive
I would like to load a new extension in a symfony2 project for twig
I want to use SwiftMailer in Symfony2. To start with, I created a new

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.