Closed ghost closed 9 years ago
I'm working on a patch for multiple primary keys as they are useful in certain curcumstances.
As for unique keys in the database, the application can never solve this issue because the application would have to do a second query to check if that value exists or not. In the time between when it returns and when you issue a query, there could have been an update that will cause the insert to not be unique. I feel that it's best to defer to the database for this issue, and not have the ORM do multiple queries (when you may not want it to be very chaty!) and then still have to catch exceptions.
@jimktrains Ok, understood. So, wait for patch!
How we know, table (by default) roles_users has 2 fields: role_id, user_id. And primary key in this table (in database level) is bunch of two fields (role_id, user_id). So, in Kohana's ORM not exist that option (I mean: declare primary key using two fields). For example (in my project, i changed some base names for my convenience (this is default Model for roles_users table) as this:
Also, about unique fields. In MySQL (for example) we can also use bunch of fields for unique values (for example id and email). So, in Kohana's ORM not exist that option too. But, in Kohana, this rule works just on rules() method (one solve of that problem is: we can catch database exception from MySQL).