symfony2admingenerator / GeneratorBundle

Admingenerator for Symfony. Parse YAML files to build customized backend.
MIT License
67 stars 29 forks source link

PropelORMFieldGuesser not working with array type #274

Open mirza99 opened 8 years ago

mirza99 commented 8 years ago

Hi,

I think I found a bug. I have an array type in the schema : <column name="roles" type="array" required="false" /> So I have an exception : Error: Call to a member function getType() on boolean that occurs in PropelORMFieldGuesser. It's because in PropelORMFieldGuesser::getOptions() the parameter $type is set to Symfony\Component\Form\Extension\Core\Type\CollectionType. And that's ok (see : here )

So I added at the beginning of the function getOptions() :

if ('virtual' === $dbType || 'ARRAY' == $dbType)
  {
            return array();
  }

_EDIT : _

Another solution is : At line 328 of PropelORMFieldGuesser :

if (preg_match("#CollectionType$#i", $type)) {
            $relation = $this->getRelation($columnName, $class);

            if ($relation) {
                return array(
                    'allow_add'     => true,
                    'allow_delete'  => true,
                    'by_reference'  => false,
                    'entry_type' => 'entity',
                    'entry_options' => array(
                        'class' => \RelationMap::MANY_TO_ONE === $relation->getType() ? $relation->getForeignTable()->getClassname() : $relation->getLocalTable()->getClassname()
                    )
                );
            }else{
                return array(
                    'entry_type' => 'text',
                );
            }
        }