1

I'm working in php laravel framework. I'm trying to add customized form fields in a page where the form field can be added dynamically.

in created Entity class (Test.php)

$class->property($this->enquiryAdditionalFields)->asType(AdditionalFormFields::collectionType());

AdditionalFormFields is an ValueObject type class, where I have defined the field name.

in created EntityMapper class (TestMapper.php):

$map->embeddedCollection(TEST::ENQUIRY_ADDITIONAL_FIELDS)
        ->toTable('enquery_additional_field')
        ->withPrimaryKey('id')
        ->withForeignKeyToParentAs('event_id')
        ->using(new AdditionalFormFieldsMapper());

AdditionalFormFieldsMapper class:

class AdditionalFormFieldsMapper extends IndependentValueObjectMapper
{
    /**
     * @param MapperDefinition $map
     * @throws \Core\Exception\InvalidArgumentException
     */
    protected function define(MapperDefinition $map)
    {
        $map->type(AdditionalFormFields::class);

        $map->property(AdditionalFormFields::FIELD_NAME)->to('field_name')->asVarchar(255);
    }
}

while adding a new field, I'm getting error as

"Could not handle action exception of type Doctrine\DBAL\Exception\NotNullConstraintViolationException from action 'edit': no matching action handler could be found"

Teletubbies
  • 43
  • 10
  • `NotNullConstraintViolationException` when adding a field to the DB, there is no values for existing rows. The field you added cannot be null, hence the exception. There are a few ways to fix it. Allow the field to be null, set a default value etc... It depends somewhat on how you define your stuff in Doctrine such as annotations, or yaml etc... – ArtisticPhoenix Oct 21 '18 at 09:49
  • Possible duplicate of [symfony2 doctrine allow null values?](https://stackoverflow.com/questions/9985531/symfony2-doctrine-allow-null-values) – ArtisticPhoenix Oct 21 '18 at 09:52
  • The duplicate is for Symfony, but it uses Doctrine as well, so it's basically the same deal in this context. – ArtisticPhoenix Oct 21 '18 at 09:53
  • I am new to this. So might ask few questions. As you can see I have custom class as "AdditionalFormField" in which I have a string type as "field_name". I have added AdditionalFormField to the Entity and EntityMapper class. According to your answer,Should I make the "field_name" or "AdditionalFormField " as nullable? – Teletubbies Oct 21 '18 at 10:42
  • It will be `field_name` as this is basically the class `AdditionalFormField ` name. The problem is in the Database, if you look in PHPmyAdmin at the table, you may see that field is set to be not-null. That said I haven't used Doctrine in about 3 years. – ArtisticPhoenix Oct 21 '18 at 10:49
  • Thanks. I have added nullable to `field_name` and migrated to dms again. But now on saving the new field, I'm getting this error as **"Invalid processed submission: expecting value for field 'field_name' to be of type string, null given staged-form.blade.php)** – Teletubbies Oct 21 '18 at 10:54
  • `staged-form.blade.php` blade is the template engine they use, you may wan't to post that as a separate question as I've never used blade. Basically instead of mixing PHP and HTML together you can use a template engine, so that issue is separate from the DB. You can probably check the data if `is_null` and put an empty string into the template instead, but I have no idea how you would do it. – ArtisticPhoenix Oct 21 '18 at 10:56

0 Answers0