Laravel Backpack - Unknown database type requested by tsvector

I am using Backpack for Laravel as my back end for object management. I have a 'show' object that is defined as such:

public function up()
    {
        Schema::create('shows', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('category_id')->nullable();
            $table->string('title');


            // Created/modified timestamps
            $table->timestamps();

        });

        // Add our search indexes
        DB::statement('ALTER TABLE shows ADD searchable tsvector NULL');
        DB::statement('CREATE INDEX shows_index ON shows USING GIN (searchable)');
    }

      

As you can see, there is a "search" column, which is a tsvector. This is important for my Postgres FTS.

Inside the CrudController for the show object, I manually define the following fields for the title and category_id:

// Title
$this->crud->addField([
    'name' => 'title',
    'label' => 'Show Title',
    'type' => 'text'
]);
$this->crud->addColumn([
    'name' => 'title',
    'label' => 'Title'
]);



// Assigned category ID
$this->crud->addField([ // Select2Multiple = n-n relationship (with pivot table)
    'label' => "Assign to Category",
    'type' => 'select2',
    'name' => 'category_id', // the db column for the foreign key
    'entity' => 'category', // the method that defines the relationship in your Model
    'attribute' => 'title', // property from the model that is shown to user
    'model' => "App\Models\Category", // foreign key model
    'data_source' => url("admin/category")
]);
$this->crud->addColumn([
    'name' => 'category_id', // The db column name
    'label' => "Category", // Table column heading
    'type' => 'select',
    'entity' => 'category',
    'model' => "App\Models\Category",
    'attribute' => 'title'
]);

      

The problem is the category_id field. While this has nothing to do with the tsvector search field, it seems like the "select2" type looks at all my columns for whatever reason, seeing the tsvector type of my "search" column and interrupting anytime I go to edit the show, I I see that the index page of the show in Backpack is just fine, but when I click Edit on a particular show I get the following error:

Unknown database type tsvector query, Doctrine \ DBAL \ Platforms \ PostgreSQL92Platform may not support it. (View: resources / species / vendor / backpack / scum / field / select2.blade.php)

If I instead try to display the category_id field as a simple text type, I get no error and it works correctly:

$this->crud->addField([
            'name' => 'category_id',
            'label' => 'Category ID',
            'type' => 'text'
        ]);
        $this->crud->addColumn([
            'name' => 'category_id',
            'label' => 'Category ID'
        ]);

      

It seems very strange to me that although I define my fields manually in my CrudController, instead of pulling each field from the database, and although I am not referring to the "search" field anyway here for select2, it is still looking at my search column seeing tsvector type and discarding me.

EDIT

I was tracking down the issue with resources / views / vendor / backpack / crud / fields / select 2.blade.php, specifically this piece of code:

@if ($entity_model::isColumnNullable($field['name']))
            <option value="">-</option>
        @endif

      

If I comment out these three lines, everything loads fine. Even though the $ ['name'] field is a "category_id" and not a tsvector "lookup" field, for some reason checking to see if it is valid breaks the whole thing. I have yet to trace this further.

+3


source to share


1 answer


I found a solution for this. Since the doctrine is not type aware of the tsvector, it needs to be registered under vendor / backpack / crud / src / CrudTrait.php

Inside the isColumnNullable () function, there is already an example of a different unsupported field type (enum) being passed to a string:

// register the enum column type, because Doctrine doesn't support it
        $conn->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');

      



After that I just added the type tsvector and now everything works correctly:

// register the tsvector column type, because Doctrine doesn't support it
        $conn->getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('tsvector', 'string');

      

+2


source







All Articles