Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Unique Key on 2 Cols


Reply


3 Posts   1516 Views

Avatar
rob.s

Community Member, 78 Posts

28 May 2010 at 12:50am

Edited: 28/05/2010 12:52am

Hi,

what is the right syntax to add a 2-col unique index ?
I'd like to have a unique index on Field_1 AND Field_2

static $indexes = array(
"Uniques" => ????,
);

in SQL would be:

...
UNIQUE KEY `myUniqueIndex` (`FIELD_1`,`FIELD_2`),
...

Avatar
rob.s

Community Member, 78 Posts

10 June 2010 at 2:24am

Edited: 10/06/2010 2:24am

no idea ?

(sry for bump)

Avatar
mark_s

Community Member, 78 Posts

11 June 2010 at 12:00pm

Edited: 11/06/2010 12:05pm

Hi.

You should be able to do this:

<code php>
static $indexes = array(
"Uniques" => array(
"type" => "unique",
"value" => "`FIELD_1`,`FIELD_2`"
)
);
</code>

Another variation is:

<code php>
static $indexes = array(
"Uniques" => "(`FIELD_1`,`FIELD_2`)",
);
</code>

But this doesn't create a unique index, just a two-column index called Uniques.

Mark