Select - placeholder - Integrity constraint violation: 1452

Select - placeholder - Integrity constraint violation: 1452

carrara.christophecarrara.christophe Posts: 6Questions: 2Answers: 0

Hello,
I have a select field which works fine when I select an option, but does not when I select the empty one coming from placeholder.

I get the common error message "An SQL error occurred: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child" that I understand but fail to solve. How should I deal with the nulll value?
I looked at this post or that one but without success.
Here is my php code:

Editor::inst( $db, 'bibliotheque_auteurs', 'auteur_id' )
    ->fields(
        Field::inst( 'bibliotheque_auteurs.auteur' )
            ->validator( Validate::notEmpty() )
            ->validator( Validate::maxLen( 40 ) )
            ->validator( Validate::unique() ),
        Field::inst( 'bibliotheque_auteurs.nationalite' )
            ->options( Options::inst()
                ->table( 'pays' )
                ->value( 'pays_id' )
                ->label( 'pays' )
            ),
        Field::inst( 'pays.pays' )
    )
    ->leftJoin( 'pays', 'pays.pays_id', '=', 'bibliotheque_auteurs.nationalite' )

And my js code

    var editor = new $.fn.dataTable.Editor( {
        ajax: 'php/table.bibliotheque_auteurs.php',
        table: '#bibliotheque_auteurs',
        fields: [
            {
                label: "Auteur:",
                name: "bibliotheque_auteurs.auteur"
            },
            {
                label: "Nationalité:",
                name: "bibliotheque_auteurs.nationalite",
                type: "select",
                placeholder: "",
                placeholderDisabled: false,
                placeholderValue: null,
            }
        ]
    } );

Any idea?

Answers

Sign In or Register to comment.