我有两个表,Clientes
和Servicios
他们有关系,我希望doctrine只返回客户端的服务而不是我使用addAction表单时存在的所有服务,例如:
`Client: Foo
Services:
Bar
Bar2
Bar3
Client: Foo2
Services:
Bar2
Bar7
Client: Foo3
Services:
Bar`
我不知道如何告诉Symfony2或Doctrine client Foo
已分配X服务......
这是教义yml
Pge\IncidenciasBundle\Entity\Clientes:
type: entity
table: clientes
id:
id:
type: integer
unsigned: false
nullable: false
generator:
strategy: IDENTITY
fields:
nombre:
type: string
length: 250
fixed: false
nullable: true
manyToOne:
servicio:
targetEntity: Servicios
cascade: { }
mappedBy: null
inversedBy: cliente
joinColumns:
servicio_id:
referencedColumnName: id
orphanRemoval: false
oneToMany:
incidencia:
targetEntity: Incidencias
cascade: { }
mappedBy: cliente
inversedBy: null
orphanRemoval: false
lifecycleCallbacks: { }
Pge\IncidenciasBundle\Entity\Servicios:
type: entity
table: servicios
id:
id:
type: integer
unsigned: false
nullable: false
generator:
strategy: IDENTITY
fields:
nombre:
type: string
length: 250
fixed: false
nullable: true
oneToMany:
cliente:
targetEntity: Clientes
cascade: { }
mappedBy: servicio
inversedBy: null
orphanRemoval: false
incidencia:
targetEntity: Incidencias
cascade: { }
mappedBy: servicio
inversedBy: null
orphanRemoval: false
lifecycleCallbacks: { }
答案 0 :(得分:1)
Doctrine无法确定哪个列应该是您的主键。
将您的ID移到yaml文件中的一个级别:
table: servicios
id:
id:
type: integer
unsigned: false
nullable: false
generator:
strategy: IDENTITY
fields:
然后运行app / console doctrine:schema:create --dump-sql
看看你得到了什么。可能还有其他错误。我看起来并不真实。如有必要,从剥离的yaml文件开始,然后一次添加一个字段。我怀疑你想要无符号也是如此。