Symfony Doctrine 模式分段错误
我正在设置我的第一个 symfony 项目,但在架构方面遇到了问题。我不确定我是否以正确的方式处理这件事。
我的两门课遇到了问题。我有客户,可以有多个联系人,需要选择其中一个联系人作为发票联系人。这是我的架构:
NativeClient:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true }
address: { type: string(255) }
postcode: { type: string(9) }
tel: { type: string(50) }
fax: { type: string(50) }
website: { type: string(255) }
client_status_id: { type: integer, notnull: true, default: 0 }
priority: { type: boolean, notnull: true, default: 0 }
invoice_contact_id: { type: integer }
invoice_method_id: { type: integer }
relations:
NativeContact: { local: invoice_contact_id, foreign: id, foreignAlias: NativeInvoiceContacts }
NativeClientStatus: { local: client_status_id, foreign: id, foreignAlias: NativeContacts }
NativeInvoiceMethod: { local: invoice_method_id, foreign: id, foreignAlias: NativeClientStatuses }
NativeContact:
actAs: { Timestampable: ~ }
columns:
client_id: { type: integer, notnull: true }
name: { type: string(255), notnull: true }
position: { type: string(255) }
tel: { type: string(50), notnull: true }
mobile: { type: string(50) }
email: { type: string(255) }
relations:
NativeClient: { onDelete: CASCADE, local: client_id, foreign: id, foreignAlias: NativeClients }
NativeClientStatus:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true }
NativeInvoiceMethod:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true }
如果我删除以下行(和相关的固定装置),它就可以工作,否则我会遇到分段错误。
NativeContact: { local: invoice_contact_id, foreign: id, foreignAlias: NativeInvoiceContacts }
会不会陷入循环?试图一遍又一遍地提及客户和联系人?任何帮助将不胜感激!谢谢!
达伦
I'm setting up my first symfony project, and am having trouble with the schema. I'm not sure if I'm going about it the right way.
I'm having a problem with two of my classes. I have Clients, which can have many Contacts, one of the contacts needs to be selected as the invoice contact. This is my schema:
NativeClient:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true }
address: { type: string(255) }
postcode: { type: string(9) }
tel: { type: string(50) }
fax: { type: string(50) }
website: { type: string(255) }
client_status_id: { type: integer, notnull: true, default: 0 }
priority: { type: boolean, notnull: true, default: 0 }
invoice_contact_id: { type: integer }
invoice_method_id: { type: integer }
relations:
NativeContact: { local: invoice_contact_id, foreign: id, foreignAlias: NativeInvoiceContacts }
NativeClientStatus: { local: client_status_id, foreign: id, foreignAlias: NativeContacts }
NativeInvoiceMethod: { local: invoice_method_id, foreign: id, foreignAlias: NativeClientStatuses }
NativeContact:
actAs: { Timestampable: ~ }
columns:
client_id: { type: integer, notnull: true }
name: { type: string(255), notnull: true }
position: { type: string(255) }
tel: { type: string(50), notnull: true }
mobile: { type: string(50) }
email: { type: string(255) }
relations:
NativeClient: { onDelete: CASCADE, local: client_id, foreign: id, foreignAlias: NativeClients }
NativeClientStatus:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true }
NativeInvoiceMethod:
actAs: { Timestampable: ~ }
columns:
name: { type: string(255), notnull: true }
If i remove the following line (and associated fixtures) it works, otherwise I get a segmentation fault.
NativeContact: { local: invoice_contact_id, foreign: id, foreignAlias: NativeInvoiceContacts }
Could it be getting in a loop? Trying to reference the Client and the Contact over and over? Any help would be greatly appreciated! Thanks!
Darren
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这个老问题,但这是一个后续解决方案。有时 Doctrine 会无缘无故地抛出这个错误。我确信有一个根本原因,但我们没有时间调试整个 Doctrine 源代码。
尝试指定 --env=[your env],它可能会起作用 - 对我来说。
Old question I know, but heres a follow up solution. Sometimes Doctrine will throw this error for seemingly no reason whatsoever. Im sure there is an underlying reason, but we dont all have time to debug the entire Doctrine source.
Try specifying --env=[your env], and it may just work - has for me.
Darren,看起来您在使用冲突的标准时定义了两端的关系......
关系是在 NativeContact 中的“invoice_contact_id”和未声明的“id”PK 之间。
... NativeClient 中的“client_id”和未声明的“id”PK 之间存在相同的关系。
我个人只在一端定义这些,然后让 Doctrine 处理其余的,但这取决于您在这里想要实现的目标。如果一个客户端有多个联系人,您可以删除第二个声明并仅在客户端表中定义关系,并添加“type: Many,foreignType: one”以声明它是一对多关系。
Darren, it seems like you're defining the relationship at both ends while using conflicting criteria...
...relationship is between "invoice_contact_id" and undeclared "id" PK in NativeContact.
... same relationship is between "client_id" and undeclared "id" PK in NativeClient.
I personally only define these in one end and let Doctrine handle the rest, but it depends on what you're trying to achieve here. If ONE client HAS MANY contacts, you could drop the second declaration and define the relationship in the clients table only and add "type: many, foreignType: one" to state that it's a one-to-many relationship.