make a weak relationship using doctrine and symfony
what im trying to do is a weak relationship between my User
table and my Confirmation
table, being Confirmation
weak of User
. To represent it, my schema is as follows:
User:
actAs: [Timestampable]
connection: doctrine
tableName: User
columns:
id:
type: integer
primary: true
autoincrement: true
username:
type: string(50)
notnull: true
name:
type: string(50)
notnull: true
.
.
.
indexes:
myindex1:
fields:
username:
sorting: ASC
length: 50
type: unique
relations:
Confirmation:
foreignType: one
attributes:
export: all
validate: true
Confirmation:
actAs: [Timestampable]
connection: doctrine
tableName: Confirmation
columns:
user_id:
type: integer
primary: true
hash:
type: string(64)
notnull: true
relations:
User:
local: user_id
foreign: id
type: one
foreignType: one
When running the command $ php symfony doctrine:build --all --no-confirmation
, i got this error in the output:
SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'id' doesn't exist in table. Failing Query: "CREATE TABLE Confirmation (user_id BIGINT, hash VARCHAR(64) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME N开发者_开发百科OT NULL, INDEX id_idx (id), PRIMARY KEY(user_id)) ENGINE = INNODB". Failing Query: CREATE TABLE Confirmation (user_id BIGINT, hash VARCHAR(64) NOT NULL, created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, INDEX id_idx (id), PRIMARY KEY(user_id)) ENGINE = INNODB
so, it seems doctrine is generating an index over a field that was not defined (id
) as you can see in INDEX id_idx (id)
. Why is doctrine generating this index? how can i model what i want?
doctrine documentation is not very extensive in relationships matters, any link to a good documentation site would be very appreciated too...
Thanks in advance for any help!!!
As far as i know, Doctrine will automatically add a column "id" per default to (all of) your table(s).
This behaviour is documented several times, and you can configure this column :
- Default identifier options
- http://www.doctrine-project.org/documentation/manual/1_1/pl/configuration:defaults-attributes:default-added-auto-id
- 3.) Removed id column as it is automatically added if no primary key is defined.
But, i'm sorry, i'dont know, if there is a way to disable this feature.
精彩评论