| multi column unique key with sfDoctrine [message #28121] |
Fri, 25 May 2007 12:01  |
ysarazin Messages: 13 Registered: March 2007 Location: France |
Junior Member |
|
|
Hello,
I'm looking to create a unique key over serveral columns in the shema.yml file.
Doctrine documentation indicate this possibility :
class User extends Doctrine_Record
{
public function setTableDefinition()
{
$this->hasColumn('name', 'string', 200);
$this->hasColumn('age', 'integer', 2);
$this->unique(array('name', 'age'));
}
}
I think something similar to :
User:
tableName: user
columns:
name: string(200)
age: integer(2)
uniques:
unique_name: [name, age]
could be working, but "uniques" is not allowed in the schema.yml :
[sfDoctrineSchemaException]
Invalid key "uniques" in description of class User
Does anybody has a solution to define such a unique key ?
|
|
|
|
|
|
|
|
| Re: multi column unique key with sfDoctrine [message #35596 is a reply to message #28121 ] |
Fri, 14 September 2007 15:18   |
sleepless Messages: 27 Registered: September 2006 |
Junior Member |
|
|
Thank for bring this up, but I discovered a bug with this code.
For some reason, the generator places the index creation code
CREATE UNIQUE INDEX a_b ON blabla(a, b);
at beginning of the generated database schema. DBMS will complain about this because it couldn't find table blabla.
However, when I tested without "type: unique", the generator generates a working database schema, in which it places the index creation code after table definition codes.
Add: Not a serious bug though, I can fix this by more the index creation code to where it suppose to be.
[Updated on: Fri, 14 September 2007 15:19]
|
|
|
|
| Re: multi column unique key with sfDoctrine [message #35640 is a reply to message #35629 ] |
Sat, 15 September 2007 00:16  |
sleepless Messages: 27 Registered: September 2006 |
Junior Member |
|
|
It'd be the same:
public function setTableDefinition()
{
$this->setTableName('photo_album_content');
$this->hasColumn('album_id', 'integer', 11, array ());
$this->hasColumn('image_id', 'integer', 11, array ());
$this->hasColumn('created_at', 'timestamp', null, array ());
$this->index('album_image_idx', array (
'fields' =>
array (
0 => 'album_id',
1 => 'image_id',
),
'type' => 'unique',
));
}
I am using PostgreSQL by the way.
|
|
|