Skip to content
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

Bug: Model save method not working if PRIMARY KEY is VARCHAR #2835

Closed
crustamet opened this issue Apr 16, 2020 · 11 comments
Closed

Bug: Model save method not working if PRIMARY KEY is VARCHAR #2835

crustamet opened this issue Apr 16, 2020 · 11 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@crustamet
Copy link
Contributor

Hello again codeigniter TEAM

i am trying to save some data into mysql database table

i have array

[0] => Array
(
    [id] => 51610677-FD05-49FC-B6B8-EC6A2B932968
    [date] => 1586855452
)

Here is my code

$Model->save([
	'id' => '51610677-FD05-49FC-B6B8-EC6A2B932968',
	'date'  => date("Y-m-d H:i:s", 1586855452)
]);

The result telling me it was a success but when im going to table i see empty table.

@crustamet crustamet added the bug Verified issues on the current code behavior or pull requests that will fix them label Apr 16, 2020
@musmanikram
Copy link
Contributor

@crustamet Can you please table schema here?

@samsonasik
Copy link
Member

Well, actually, for uuid, you should use binary instead of varchar. But if you can give reproducible use case, probably someone or you can propose a fix.

@michalsn
Copy link
Member

Not a bug. If you use save() method and at the same time you have an id in the array, the model class will try to make an update, not insert.

Just use insert() method instead.

Oh... btw, I'm not sure if the default model will play nice with UUID field as a primary key - probably not. You will have to make some amends to the way it works, by extending it, because it uses insertID in some places.

@crustamet
Copy link
Contributor Author

this is shit, just use insert insted of save lol, this beats the purpose of using save, i have to work extra because codeigniter still doesn't know if i have a record in databse ? or not ? whats the point of even using save() then ?

@crustamet
Copy link
Contributor Author

@crustamet Can you please table schema here?

there are two keys varchar primary key that is not autoincrement. and a date datetime.

@michalsn
Copy link
Member

@crustamet This is an open-source project. If you don't like how some things work and see a place for improvements, you can always send a PR.

@crustamet
Copy link
Contributor Author

No man, i am sorry, it is all good,

I can`t send a PR because my method will not be good :)

They think everything trough already.
The save function only works with a standard database table.

The only problem that i am complaining about it is the return IS TRUE while it didn`t do anything.
Ofcourse it returns TRUE because the save method updates nothing because it thinks it already exists.

I went down the rabbit hole :)

The thing here is when the query gets executed, it execute with success and the save method return true if no errors occurred, but it should return how many rows changed in the database.

Anyway it is good like this.

@crustamet
Copy link
Contributor Author

Until the end of the day this is a legit issue or not ?

@michalsn
Copy link
Member

Not. Everything is working as it supposed to work and as described in the docs.

Also the default Model class supports only auto-increment fields for a primary key.

@luispastendev
Copy link

@crustamet What are you using to generate the uuids? I find the option that the model methods can work with something other than auto_increments quite interesting.

@crustamet
Copy link
Contributor Author

i get the uids from an API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

6 participants