-
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
Model's without primary keys get pagination counts wrong #1597
Comments
Hi, I just noticed |
There is no point of keeping the statement, $sql = ($this->QBDistinct === true) ? $this->countString . $this->db->protectIdentifiers('numrows') . "\nFROM (\n" . $this->compileSelect() . "\n) CI_count_all_results" : $this->compileSelect($this->countString . $this->db->protectIdentifiers('numrows')); This should work with, |
@atishamte Not sure where you're referring to with that query. However, the more I think about this the less I'm concerned with having it work without a primary key. As we've added a bunch of new features to the model, many do rely on having a primary key to work. Many people also want an ORM and if that's ever going to happen, it's likely that we'll need to have primary keys on models. So - closing this because we won't support that in models. I'll have it throw an exception when a model doesn't have a primary key so it's obvious. |
I was referring to the countAllResult function body |
…from becoming a tangled mess, and partially to ensure all Model convenience features work both now and in the future. Closes #1597
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.
I want to count how many result for pagination so I used
$query->countAllResults()
to count it, the result was '2', I don't know where '2' came from.I then tried to view the result using
$query->getResult()
, it shows '5' results correctly.$query->paginate()
shows correct result as well.Here's the test code I used
Because there's no
$this->db->last_query();
, I don't know what kind of querycountAllResults
produced.Originally posted by @cobafesbuk in #1583 (comment)
The text was updated successfully, but these errors were encountered: