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
Make the Model work without auto_increment primary key #3134
Comments
It's not really a bug - more like a feature request. Contributions are always welcomed - but please be sure to add some tests, to make sure this change would not break anything. Also, take into consideration that we have to support |
For get inserted primary key value, the best way is using "RETURNING primaryKey" in query, but database driver dont know primary key, model can't change SQL string. I dont know a way A create initial PR, how much could https://github.com/MashinaMashina/CodeIgniter4/tree/Model_without_autoincrement_key |
@MashinaMashina I think you should create a PR. This way we can easier discuss your code. In general, if the "auto increment" option is disabled and there is no Additionally, we will need some tests and docs updates. If you're willing to work on this I will be glad to help with your questions if you will have any. |
I wanted this feature before, this going to be commited ? or it will just remain like it is right now ? |
@crustamet There is nothing we can merge yet. I'm not sure if @MashinaMashina will try to work on this though. If you're motivated enough, you can prepare a PR for this, but we will need some tests too. |
@michalsn Do we have tests for Model.php? |
@michalsn I try to create tests, but it runs on sqllite, not postgres https://github.com/MashinaMashina/CodeIgniter4/tree/Model_without_autoincrement_key Is good this? |
@MashinaMashina This is the default behavior. You can change If you will be ready, please send a PR so we can review your changes. |
@michalsn how do work postgres on tests? I dont know access to postgres on tests |
@MashinaMashina Just adjust the |
I just found out the model without a primary key works as intended, the problem with update is a little bit weird how you need to update the row. But this works only if you have one row in your table. If you have multiple rows i don't see why you don't need a primary key. Example
When you insert
When you update
I think the update works even without the where(1, 1); but i didn't test this. |
Describe the bug
I can create PR, but without description. I think to create property CodeIgniter\Model::$has_autoincrement and add checking it in \system\Model.php:731, but I don't know if is a good idea
The text was updated successfully, but these errors were encountered: