Symfony tries to create related record when updating

32 Views Asked by At

I am trying to edit a record that has a FK and even though im passing null for the FK it is trying to create a record in the related table.

The issue is the same as : Symfony (doctrine) try to insert null related object while saving

Only that I am able to submit the form and create a row the first time but cannot edit it from there on.

SCHEMA

DigestSettings:
  actAs:
    Timestampable : ~
    I18n:
      fields: [subject, title, email_subject]
  columns:
    active: { type: boolean, notnull: false, default: 0 }
    autosend: { type: boolean, notnull: false, default: 0 }
    start_date: { type: timestamp, notnull: false }
    frequency: { type: integer(11), notnull: true, default: 0 }
    recipient_type: { type: integer(11), notnull: true, default: 0 }
    email_subject: { type: string(255), notnull: true  }
    tenant_id: { type: integer, notnull: false }
    exclude_users: { type: clob(65555), notnull: false, default: null }
    recipients_filter_id: { type: integer(11), notnull: false, default: null }
    title: { type: string(255), notnull: false }
    additional_users: { type: clob(65555), notnull: false, default: null }
    subscribed_users: { type: clob(65555), notnull: false, default: null }
    receive_default: { type: boolean, notnull: true, default: 0 }
  relations:
    Tenant: { class: Tenant, local: tenant_id, foreign: id, onDelete: CASCADE, onUpdate: CASCADE }
    recipientsFilter: { class: Filters, local: recipients_filter_id, foreign: id, onDelete: SET NULL }

The error that im getting is SQLSTATE[HY000]: General error: 1364 Field 'filter_type' doesn't have a default value so the field that fails is recipients_filter_id

BaseClass

abstract class BaseDigestSettingsForm extends BaseFormDoctrine
{
    public function setup()
    {
        $this->setWidgets([
            'id'                   => new sfWidgetFormInputHidden(),
            'active'               => new sfWidgetFormInputCheckbox(),
            'autosend'             => new sfWidgetFormInputCheckbox(),
            'start_date'           => new sfWidgetFormDateTime(),
            'frequency'            => new sfWidgetFormInputText(),
            'recipient_type'       => new sfWidgetFormInputText(),
            'tenant_id'            => new sfWidgetFormDoctrineChoice(['model' => $this->getRelatedModelName('Tenant'), 'add_empty' => true]),
            'exclude_users'        => new sfWidgetFormTextarea(),
            'recipients_filter_id' => new sfWidgetFormDoctrineChoice(['model' => $this->getRelatedModelName('recipientsFilter'), 'add_empty' => true]),
            'additional_users'     => new sfWidgetFormTextarea(),
            'subscribed_users'     => new sfWidgetFormTextarea(),
            'receive_default'      => new sfWidgetFormInputCheckbox(),
            'created_at'           => new sfWidgetFormDateTime(),
            'updated_at'           => new sfWidgetFormDateTime(),
0

There are 0 best solutions below