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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:07:54+00:00 2026-05-21T03:07:54+00:00

I have a many-to-many relation in symfony 1.4. I am using the Doctrine admin

  • 0

I have a many-to-many relation in symfony 1.4. I am using the Doctrine admin generator, and would like to add an “Is Empty” checkbox to the standard sfWidgetFormDoctrineChoice for that field, to do a “WHERE NOT EXISTS” query and find untagged entries. Anyone seen a solution for this?

Thank you!

  • 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-05-21T03:07:54+00:00Added an answer on May 21, 2026 at 3:07 am

    widget:

    class ynWidgetFormDoctrineChoiceEmpty extends sfWidgetFormDoctrineChoice
    {
      protected function configure( $options = array(), $attributes = array() )
      {
        parent::configure( $options, $attributes );
    
        $this->addOption( 'with_empty', false );
        $this->addOption( 'empty_label', 'none' );
        $this->addOption( 'template', '%select%<div>%empty_checkbox% %empty_label%</div>' );
      }
    
      public function render( $name, $value = null, $attributes = array(), $errors = array() )
      {
        $select = parent::render( $name, $value, $attributes, $errors );
    
        if ( $this->getOption('with_empty') ) {
          $values = array_merge(array('text' => '', 'is_empty' => false), is_array($value) ? $value : array());
    
          return strtr($this->getOption('template'), array(
            '%select%'         => $select,
            '%empty_checkbox%' => $this->renderTag('input', array('type' => 'checkbox', 'name' => $name.'[is_empty]', 'checked' => $values['is_empty'] ? 'checked' : '')),
            '%empty_label%'    => $this->renderContentTag('label', $this->translate($this->getOption('empty_label')), array('for' => $this->generateId($name.'[is_empty]'))),
          ));
        }
        else {
          return $select;
        }
      }
    }
    

    validator:

    class ynValidatorDoctrineChoiceEmpty extends sfValidatorDoctrineChoice
    {
      public function configure( $options = array(), $messages = array() )
      {
        parent::configure( $options = array(), $messages = array() );
    
        $this->addMessage('empty_or_not', 'Select either choices or none');
      }
    
      protected function doClean( $values )
      {
        if (
          isset( $values['is_empty'] )
          && $values['is_empty'] == 'on'
        ) {
          if ( count( $values ) > 1 ) {
            // 'empty' selected alongside subjects
            throw new sfValidatorError( $this, 'empty_or_not' );
          }
    
          return $values;
        }
        else {
          return parent::doClean( $values );
        }
      }
    }
    

    in FooFormFilter:

    public function addBarListColumnQuery( Doctrine_Query $query, $field, $values )
    {
      if (!is_array($values))
      {
        $values = array($values);
      }
    
      if (!count($values))
      {
        return;
      }
    
      if (
        isset( $values['is_empty'] )
        && $values['is_empty'] == 'on'
      ) {
        $query
          ->andWhere('NOT EXISTS (SELECT fb.bar_id '
            . 'FROM FooBar fb where ' . $query->getRootAlias()
            . '.id=fb.foo_id)');
      }
      else {
        $query
          ->leftJoin($query->getRootAlias().'.FooBar FooBar')
          ->andWhereIn('FooBar.bar_id', $values)
        ;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Symfony and Doctrine, and have several many-to-many relations that work fine. But
I have a many-to-many relationship defined in my Symfony (using doctrine) project between Orders
I have 3 tables: Book, Section and Content. I want to add many-to-many relation
my situation is that i have one to many relation ,like order and orderdetails
I have a product table that has a many-to-many relation to itself (using a
I am using Symfony 2.0.10 with Doctrine 2.1 and have rather simple query (see
I have a little disturbing problem in here! an using symfony 1.4 with Doctrine!
I have a many To many relation in my resource classes using hibernate. In
I'm using Linq to Sql and have a Many-To-Many relation and therefore use a
I have db scheme where Product table have many to many relation to Color

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.