Closed DhPandya closed 1 year ago
Probably it is better to use getInsertID()
.
https://codeigniter4.github.io/CodeIgniter4/models/model.html#insert
Why do you think it should be documented? How do you use it?
I believe this property is pointless and should be removed. When inserting data, the new ID must be returned as part of the data. It is not part of the model, since each new query to the database will change the state of this property.
dd ($user->insert(['name' => 'kenjis']));
// [
// 'name' => 'kenjis',
// 'created_at => '1970-01-01'
// 'id' => 1
// ]
I don't know the Model should return the inserted record or not. At least, the current Model does return insert ID or bool.
As you say, the property is a bit odd, but the getInsertID() method is clearly documented.
You can retrieve the last inserted row’s primary key using the getInsertID() method. https://codeigniter4.github.io/CodeIgniter4/models/model.html#insert
I don't know the Model should return the inserted record or not. At least, the current Model does return insert ID or bool.
As you say, the property is a bit odd, but the getInsertID() method is clearly documented.
You can retrieve the last inserted row’s primary key using the getInsertID() method. https://codeigniter4.github.io/CodeIgniter4/models/model.html#insert
Yes you're absolutely right. The getInsertId() is enough for the id. But when we generate the model using CLI the property $InsertId comes with. But there is no use of this property in the System model as well. So i was checking the document and i didn't find it in the document also.
I sent a PR to remove $insertID in make:model
template.
PHP Version
8.1
CodeIgniter4 Version
4.3.3
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
No response
What happened?
$insertID doc is missing from the model docs.
Steps to Reproduce
N/A
Expected Output
N/A
Anything else?
No response