LogicException Table does not have a primary key

_rasel^
Member | 59
+
0
-

Hi, is there any way to disable the PK check please? I use the ublaboo/datagrid and \PdfResponse libraries, and in practice it turns out that it is much more convenient to use view to display data (which contains dozens of joins and conditions) than to write joins in PHP for both practical and functional reasons, reusability and uniform placement. Moreover, it is not possible to write advanced joins in PHP that would support e.g. “outer apply” (in MSSQL). View obviously don't have a primary ID. I also use tabular functions to stretch data to datagrid/PDF, which also don't have PK. I have $grid->setPrimaryKey(‘<id>’) defined in datagrid, but still this error returns from time to time and quite regularly. I have stored the id as a persistent parameter. It's pretty stupid to instruct users to try clicking the button again in case it doesn't work…

Solution?

  1. It is probably most appropriate to only check for the existence of PKs for tables and not for views, table functions, etc.
  2. To be able to specify directly at db model level a column with PK
  3. Or that the error be shown as a warning in the log and not as an error to the user.

I understand that IDs are used for the following reasons: speed, paging, to ensure correct identification during update/insert. But in the view primary it is not possible to specify the ID…

bohacf
Backer | 8
+
0
-

_rasel^ wrote:

Hi, is there any way to disable the PK check please? I use the ublaboo/datagrid and \PdfResponse libraries, and in practice it turns out that it is much more convenient to use view to display data (which contains dozens of joins and conditions) than to write joins in PHP for both practical and functional reasons, reusability and uniform placement. Moreover, it is not possible to write advanced joins in PHP that would support e.g. “outer apply” (in MSSQL). View obviously don't have a primary ID. I also use tabular functions to stretch data to datagrid/PDF, which also don't have PK. I have $grid->setPrimaryKey(‘<id>’) defined in datagrid, but still this error returns from time to time and quite regularly. I have stored the id as a persistent parameter. It's pretty stupid to instruct users to try clicking the button again in case it doesn't work…

Solution?

  1. It is probably most appropriate to only check for the existence of PKs for tables and not for views, table functions, etc.
  2. To be able to specify directly at db model level a column with PK
  3. Or that the error be shown as a warning in the log and not as an error to the user.

I understand that IDs are used for the following reasons: speed, paging, to ensure correct identification during update/insert. But in the view primary it is not possible to specify the ID…

Hi, it's a good idea, but still not implemented :(

Workaround is here:
https://forum.nette.org/…-pohled-view#…
https://forum.nette.org/…lare-a-latte#…

Issue in nette/database: https://github.com/…e/issues/311

Last edited by bohacf (2024-08-28 14:53)