j4mie / idiorm

A lightweight nearly-zero-configuration object-relational mapper and fluent query builder for PHP5.
http://j4mie.github.com/idiormandparis/
2.01k stars 369 forks source link

compound primary key #343

Closed tbowmo closed 6 years ago

tbowmo commented 6 years ago

Am I correct, that compound primary keys are not supported?

I have a table like:

CREATE TABLEanswer( nerdIdint(11) NOT NULL, invitationIdint(11) NOT NULL, attendingtinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (nerdId,invitationId), KEYto(invitationId), CONSTRAINTfromFOREIGN KEY (nerdId) REFERENCESnerd(id) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINTtoFOREIGN KEY (invitationId) REFERENCESinvitation(id) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

and trying to query with: $answer = ORM::for_table('answer')->find_one(Array('nedId' => 2, 'invitationId' => 1);

gives me the following error: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

I then switched to use raw_query(), which retrieved the record.. But when saving, I get an error with primary key ID missing..

tbowmo commented 6 years ago

Should have read the documentation better..

Reading this, helped me solve the issue https://idiorm.readthedocs.io/en/latest/configuration.html#id-column