-
-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MySQL Views: LogicException Table does not have a primary key #311
Comments
Why are you using Selection as your data source? Use |
See the original post: The only issue is the missing primary key for views; otherwise, |
I didn't find the reason why you have to use Selection in the original post. Anyway, the Selection layer needs to know the PK by the principle of its work. But you can use StaticConventions and specify the primary key hardcoded. It can be set up probably via |
I see. But wouldn't it be more appropriate to allow set PK via DiscoveredConventions works well, except for those views. |
Version: 3.2
Bug Description
Nette/Database/Table/Selection can't work with database views because they don't have a primary key and
$selection->getPrimary()
throws an exception.Full Description
Here is a detail from this unresolved post: https://forum.nette.org/en/35718-logicexception-table-does-not-have-a-primary-key
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(‘’) 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…
Proposed solution
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…
Possible workaround
custom
$selection->getPrimary()
https://forum.nette.org/cs/36357-database-explorer-pro-databazovy-pohled-view#p226108
https://forum.nette.org/cs/34856-planuje-se-exploreru-pridat-podporu-datovych-typu-jako-to-maji-formulare-a-latte#p217958
The text was updated successfully, but these errors were encountered: