Compare values in serialized column in Doctrine with Query Builder
        Posted  
        
            by 
                ReynierPM
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by ReynierPM
        
        
        
        Published on 2014-08-20T04:15:37Z
        Indexed on 
            2014/08/20
            4:20 UTC
        
        
        Read the original article
        Hit count: 294
        
I'm building a FormType for a Symfony2 project but I need some Query Builder on the field since I need to compare some values with the one stored on DB and show the results. This is what I have:
....
->add('servicio', 'entity', array(
    'mapped' => false,
    'class' => 'ComunBundle:TipoServicio',
    'property' => 'nombre',
    'required' => true,
    'label' => false,
    'expanded' => true,
    'multiple' => true,
    'query_builder' => function (EntityRepository $er) {
            return $er->createQueryBuilder('ts')
                        ->where('ts.tipo_usuario = (:tipo)')
                        ->setParameter('tipo', 1);
        }
))
....
But tipo_usuario at DB table is stored as serialized text for example:
record1: value1 | a:1:{i:0;s:1:"1";}
record2: value2 | a:4:{i:0;s:1:"1";i:1;s:1:"2";i:2;s:1:"3";i:3;s:1:"4";}
I'll have two different forms (I don't know how to pass the Request to a form) in the first one I'll only show the first record and for the second one the first and second record for example:
First form will show:
checkbox: value1
Second form will show:
checkbox: value1
checkbox: value2
I achieve this? Any help?
© Stack Overflow or respective owner