some_type
表仅用于将foo.type
的允许值限制为some_table.type
中的值,并且将永远不会创建SomeType
实体。 Foo
应该具有属性type
,但不能具有属性someType
。如果删除<many-to-one target-entity="SomeType">...</many-to-one>
,则Foo#someType
将根据需要删除,但外键将从架构中删除。如何指示Doctrine保留外键而不生成Foo#someType
?
SomeType
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="SomeType" table="some_type">
<id name="type" type="string" column="type" length="8"/>
</entity>
</doctrine-mapping>
Foo
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Foo" table="foo">
<indexes>
<index name="fk_foo_some_type_idx" columns="type"/>
<index name="fk_foo_bar1_idx" columns="bar_id"/>
</indexes>
<id name="id" type="integer" column="id">
<generator strategy="IDENTITY"/>
</id>
<field name="type" type="string" column="type" length="8"/>
<many-to-one target-entity="SomeType">
<join-columns>
<join-column name="type" referenced-column-name="type"/>
</join-columns>
</many-to-one>
<many-to-one field="bar" target-entity="Bar" inversed-by="foos" fetch="LAZY">
<join-columns>
<join-column name="bar_id" referenced-column-name="id" nullable="false"/>
</join-columns>
</many-to-one>
</entity>
</doctrine-mapping>