Codeigniter4: Compound primary-key not supported

Created on 7 May 2019  路  5Comments  路  Source: codeigniter4/CodeIgniter4

Describe the bug
Trying to set a model with compound primary-key (two or more columns) is not supported by Codeigniter Model and DB Builder

CodeIgniter 4 version
4.0.0.beta.3

Affected module(s)
Codeigniter Model and DB Builder

Expected behavior, and steps to reproduce if appropriate
1) Define a compound primary-key table. (E.g. book_author which pk be: book_id,author_id)
2) Set $this->primaryKey as array ['book_id', 'author_id']
3) Try to get a row with $this->find()
4) An Exception is thrown because 'array cannot be parsed as a string'

Context

  • OS: Debian 9
  • Web server: Apache 2
  • PHP version 7.3
enhancement

All 5 comments

I did that in my copy of CI4 cuz I needed it.
In fact, I did it by extending the Model class but only for insert / update method with a little dirty code.

As for now, CI4 has been implemented (as I understood from PRs, issues comments) with no support for compound PKs. :(

@nowacki sure, I could do by myself but I think that should be supported in a future since other way the framework would force you to use not normalized database/table.

@rino7 - that's true :(
OFC I could share my solution, but it is dirty and I am not proud about if even if it works well.

@nowackipawel Will appreciate if you could share your code with me

Pls, send me remainder to my email (you will find mine on my profile page). I cannot find yours on your profile page. I will share it in next few days (maybe you made me that way to improve sth, but I don't think so;-)), but please do not except hi-quality code I wrote it to get basic support for that kinda PKs.

Was this page helpful?
0 / 5 - 0 ratings