2017-06-30 10 views
3

私はLaravelのバックパックをエンティティ管理のバックエンドとして使用しています。あなたがのtsvectorである「検索可能」列がある見ることができるようにLaravel Backpack - 不明なデータベースタイプtsvectorが要求されました

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)'); 
    } 

:私はそのように定義された「ショー」の実体を、持っています。これは私のPostgres FTSにとって重要です。ショーのエンティティのCrudController以内

、私は手動で私のタイトルと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' 
]); 

問題がCATEGORY_IDフィールドです。検索可能なtsvectorフィールドとは何の関係もありませんが、何らかの理由で 'select2'タイプがすべてのカラムを調べていて、 '検索可能な'カラムのtsvectorタイプを見て、いつでも私がショーを編集することができます。私はバックパックの中にうまくショーのインデックスページを見ることができますが、私は特定の番組で[編集]をクリックしたときに、私は次のエラーを取得する:

Unknown database type tsvector requested, Doctrine\DBAL\Platforms\PostgreSQL92Platform may not support it. (View: resources/views/vendor/backpack/crud/fields/select2.blade.php)

私が代わりにシンプルなテキスト型としてCATEGORY_IDフィールドを表示しようとすると、私はエラーを取得していないし、それが正常に動作します:

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

私が私のCrudControllerに手動で自分のフィールドを定義するのではなく、データベースからすべてのフィールドを引っ張って、私はありませんが、よもののように私には非常に奇妙なようですselect2のために私の '検索可能な'フィールドをここでどのように参照しても、それはまだ私の '検索可能な'カラムを見ていて、tsvectorタイプを見て、私をあきらめている。

EDIT

私はリソース/ビュー/ベンダー/バックパック/ CRUD /フィールド/ select2.blade.php、コードの特にこのチャンクに問題をトレースしました:

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

これらの3行をコメントアウトすると、すべてが正常に読み込まれます。 $ field ['name']は 'category_id'で、tsvectorの 'searchable'フィールドではありませんが、何らかの理由でnullableであるかどうかをチェックすることですべてが破られます。私はまだこれをさらに追跡していません。

答えて

2

私はこのために自分自身で解決策を見つけました。 doctrineはtsvectorタイプを認識していないので、vendor/backpack/crud/src/CrudTrait.phpに登録する必要がありました。

isColumnNullable()関数内には、すでにサポートされていない別のフィールドタイプ)文字列にキャストされている:

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

私は単純に、その後のtsvectorタイプを追加し、すべてが正しく動作するようになりました:

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