I have a table that uses an auto-incremented primary key and it has several fields.
我有一个表使用自动递增的主键,它有几个字段。
<column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true" />
<column name="field1" type="INTEGER" required="true" />
<column name="field2" type="INTEGER" required="true" />
<column name="field3" type="INTEGER" />
<column name="field4" type="INTEGER" />
<column name="field5" type="INTEGER" />
I want to make sure that a field1
+ field2
combo isn't used more than once, so I added them as primary keys in addition to the id, but this is creating problems when I try to use findPK()
. I would prefer to have an auto-incremented id as primary key but I also want to make sure that the combo field1
+ field2
isn't entered more than once.
我想确保field1 + field2组合不会被多次使用,所以除了id之外我还将它们作为主键添加,但是当我尝试使用findPK()时这会产生问题。我希望有一个自动递增的id作为主键,但我也想确保combo field1 + field2不会多次输入。
<column name="id" type="INTEGER" primaryKey="true" required="true" autoIncrement="true" />
<column name="field1" type="INTEGER" required="true" primaryKey="true" />
<column name="field2" type="INTEGER" required="true" primaryKey="true" />
2 个解决方案
#1
4
Try setting an unique index on those fields, something like :
尝试在这些字段上设置唯一索引,例如:
<unique>
<unique-column name="/field1/" />
<unique-column name="/field2/" />
</unique>
as per propel doc
根据推进文件
#2
0
And here is the answer for doctrine with yaml
以下是与yaml一起学说的答案
Pet:
columns:
pet_name: {type: string(32)}
owner_id: {type: integer}
indexes:
owner_name:
fields: [pet_name, owner_id]
type: unique
#1
4
Try setting an unique index on those fields, something like :
尝试在这些字段上设置唯一索引,例如:
<unique>
<unique-column name="/field1/" />
<unique-column name="/field2/" />
</unique>
as per propel doc
根据推进文件
#2
0
And here is the answer for doctrine with yaml
以下是与yaml一起学说的答案
Pet:
columns:
pet_name: {type: string(32)}
owner_id: {type: integer}
indexes:
owner_name:
fields: [pet_name, owner_id]
type: unique