Laravel Backpackを使用しているWebサイトのバックエンドパネルを構築しています。本当にいいですが、私は関係クエリが非常に高価であることに気付きました。 製品とそれらの間の多くの関係に多くのとセンター:Laravel Backpackのn-n関係でクエリを最適化
私は2つのモデルがあります。私のCenterCrudControllerでは、私はフィールドをこのように定義しています
$this->crud->addColumns([
// More fields...
[
'label' => 'Products',
'type' => 'select2_multiple',
'name' => 'products', // the method that defines the relationship in your Model
'entity' => 'products', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\Product', // foreign key model
'pivot' => true, // on create&update, do you need to add/delete pivot table entries?
],
// More fields...
]);
それは、関連するモデルを選択し、複数のフィールドを示し、正常に動作します。しかし、使用されるクエリはSELECT * FROM products
です。これは非常に高価です(テーブル製品には約25列のレコードが数千件あります)。
この例では私だけIDと名フィールドが必要です。私はQuery Builder select()
メソッドのようなものを探しています。
このタイプのクエリを最適化する方法はありますか?
ありがとうございます!
getを使用して選択しようとしましたか? - > get(['id'、 'name']) –
@AshishPatel:ありがとうございますが、私はそれをどのように使用するかを理解できません。メソッド 'CrudPanel :: get()'は存在しません。あなたはそれを説明できますか? – Diego
[select2_from_ajaxフィールド](https://laravel-backpack.readme.io/docs/crud-fields#section-select2_from_ajax)はあなたにとって最適ですと思います。 – tabacitu