我从Symfony2和Doctrine开始。既然我有第一个行动,包括通过运行doctrine进行数据库交互,我想为两个实体创建一个manyToOne关联。我从一开始就开始使用YAML中的Doctrine配置文件定义模型。
E.g。 (已包括manyToOne协会)
Carsetup\MainBundle\Entity\VehicleWheelCombination:
type: entity
table: vehicle_wheel_combination
indexes:
vehicle_wheel_combinations_rim:
columns:
- rim_id
vehicle_wheel_combinations_spacer:
columns:
- spacer_id
vehicle_wheel_combinations_tyre:
columns:
- tyre_id
vehicle_wheel_combinations_vehicles:
columns:
- vehicle_id
id:
id:
type: integer
nullable: false
unsigned: false
comment: ''
id: true
generator:
strategy: IDENTITY
fields:
streetLegal:
type: boolean
nullable: false
comment: ''
column: street_legal
manyToOne:
rim:
targetEntity: Rim
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
rim_id:
referencedColumnName: id
orphanRemoval: false
spacer:
targetEntity: Spacer
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
spacer_id:
referencedColumnName: id
orphanRemoval: false
tyre:
targetEntity: Tyre
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
tyre_id:
referencedColumnName: id
orphanRemoval: false
vehicle:
targetEntity: Vehicle
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
vehicle_id:
referencedColumnName: id
orphanRemoval: false
manyToOne:
rating:
targetEntity: Rating
cascade: { }
mappedBy: null
inversedBy: null
orphanRemoval: false
lifecycleCallbacks: { }
基于这些配置,我生成了实体。当我现在重新生成实体时,没有创建关联的getter或setter。使用的命令:
php app/console doctrine:generate:entities Carsetup/MainBundle/Entity/VehicleWheelCombination
是的,我可以直接在实体中创建关联,但我无法理解的是:配置文件的实际原因是什么?为什么我不首先创建实体?或者我做错了什么?
谢谢!
答案 0 :(得分:0)
我得到了它的工作。我不想保留其他可能遇到类似问题的orm.yml文件。这是我关注实体的工作原则配置文件:
Carsetup\MainBundle\Entity\VehicleWheelCombination:
type: entity
table: vehicle_wheel_combination
indexes:
vehicle_wheel_combinations_rim:
columns:
- rim_id
vehicle_wheel_combinations_spacer:
columns:
- spacer_id
vehicle_wheel_combinations_tyre:
columns:
- tyre_id
vehicle_wheel_combinations_vehicles:
columns:
- vehicle_id
id:
id:
type: integer
nullable: false
unsigned: false
comment: ''
id: true
generator:
strategy: IDENTITY
fields:
streetLegal:
type: boolean
nullable: false
comment: ''
column: street_legal
manyToOne:
rim:
targetEntity: Rim
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
rim_id:
referencedColumnName: id
orphanRemoval: false
spacer:
targetEntity: Spacer
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
spacer_id:
referencedColumnName: id
orphanRemoval: false
tyre:
targetEntity: Tyre
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
tyre_id:
referencedColumnName: id
orphanRemoval: false
vehicle:
targetEntity: Vehicle
cascade: { }
mappedBy: null
inversedBy: null
joinColumns:
vehicle_id:
referencedColumnName: id
orphanRemoval: false
oneToMany:
rating:
targetEntity: Rating
cascade: { }
mappedBy: vehicleWheelCombination
inversedBy: null
orphanRemoval: false
lifecycleCallbacks: { }