Jordi Casals Fri Dec 14 10:37:38 -0500 2012

Subject: Composite keys

Hi all,

I was wondering if there is a possibility of using Composite Keys as $primary_key in a model definition. I googled it and it seems that it is not possible, but maybe I am not searching it in the right way.

My idea is to have this, but I think that the value of $primary_ley must be a string and not an array.

static $primary_key = array('date','storage_group','library','file_family');


Thank you very much!

Devin Moore Mon Dec 31 10:19:46 -0500 2012

Are you trying to use a 'composite' key as a way to verify uniqueness between two records? If this is the case, you don't need to worry about creating a composite key, but simply use the uniqueness abilities against multiple columns (IE, a record cannot be created/updated if another record already exists with the same data for the columns 'date', 'storage_group', 'library', and 'file_family').

Using the phpactive record abilities, you can use this to pre-validate before creating/updating a record:

Otherwise, you can creating unique column definitions based on a combination of different columns. This would be specific to the type of database you are using, (MySQL, PostgreSQL , etc...).