-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Cannot use Model first() and update() in table without primary key #1583
Comments
My PR#1325 or newer PR#1560 should solve your issue about update([col => 2, bar => [1,3]]) method. The same with delete() method or PR#1441 |
table without primary key is not good idea. |
I cannot agree with you. It depends what you are storing in it. |
@nowackipawel I'm curious what type of stuff you store that doesn't need a primary key? Doesn't that result in full table scans whenever you query? |
@lonnieezell I had in my mind that we could have complex primary keys and then it is important to specified it easy in the update query like: WHERE X = 1 and y = 4 and that is what PR#1325 or PR#1560 is doing well :). However you ask about use case:.... I don't use primary keys in "storage-like" tables like login attempts when I am sure I won't need it sometimes I've got at max 3-4 tables like that in database which contains 60-70 tables. |
You can write like this. |
Or like this. |
@nowackipawel I guess that makes sense. I've always still put a primary key in there because otherwise it will do a full table scan whenever you search and if those tables starting getting big, which a login attempts table likely will, that query is going to keep getting slower when I need to get there. Sounds like they are tables you don't access very much so likely not a pain point for you. |
This particular issue sounds like it's simple enough to fix, though, by checking to see if primary key is empty or not before adding the order by into the query. |
Not directly related to the report (OUT OF TOPIC) It seems that I encountered another issue because of not using primary key. It seems that the new CodeIgniter's design is built around primary key system? I supposed to have '5' results from my query. Here's the test code I used
Because there's no |
@titounnes
|
$this->model->set('name', $input['name']); |
Describe the bug
When using a table without primary key, it's not possible to use
first()
command.I found the reason is
'ORDER BY <tablename>.<primary key>'
is always appended to the end of the query.Emptying the
$primaryKey
does not fix the problem.Similiar problem with
update()
. It works fine withinsert()
.I'm using the query builder for workaround for now.
CodeIgniter 4 version
CodeIgniter 4.0.0 alpha.2
Context
The text was updated successfully, but these errors were encountered: