I have a table with columns color_id
and list_id
. When I load a page with that specific model in Laravel BackPack, it throws an error:
SQLSTATE[42703]: Undefined column: 7 ERROR: column "id" does not exist LINE 1: select * from "color_list" order by "id" desc l... ^ (SQL: select * from "color_list" order by "id" desc limit 10)
In general, this is correct. I do not have an id
column since it’s a pivot table. I assumed adding custom sorting would solve the problem so I added the following line in my controller’s setup()
method:
$this->crud->addClause('orderBy', 'color_id', 'DESC');
This didn’t solve the problem and BackPack is still trying to search id
column.
SQLSTATE[42703]: Undefined column: 7 ERROR: column "id" does not exist LINE 1: ...color_list" order by "color_id" desc, "id" desc ... ^ (SQL: select * from "color_list" order by "color_id" desc, "id" desc limit 10)
Is there no way around it? Do I really need to add an id
column to my table?
Advertisement
Answer
By adding this to my model, I was able to solve it for the moment:
protected $primaryKey = 'color_id';
But is this really the only solution?