Symfony Doctrine 模式分段错误

发布于 2024-08-23 01:28:18 字数 2008 浏览 5 评论 0原文

我正在设置我的第一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尝蛊 2024-08-30 01:28:18

我知道这个老问题,但这是一个后续解决方案。有时 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.

轻许诺言 2024-08-30 01:28:18

Darren,看起来您在使用冲突的标准时定义了两端的关系......

NativeContact:       { local: invoice_contact_id, foreign: id, foreignAlias: NativeInvoiceContacts }

关系是在 NativeContact 中的“invoice_contact_id”和未声明的“id”PK 之间。

 NativeClient:       { onDelete: CASCADE, local: client_id, foreign: id, foreignAlias: NativeClients } 

... 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...

NativeContact:       { local: invoice_contact_id, foreign: id, foreignAlias: NativeInvoiceContacts }

...relationship is between "invoice_contact_id" and undeclared "id" PK in NativeContact.

 NativeClient:       { onDelete: CASCADE, local: client_id, foreign: id, foreignAlias: NativeClients } 

... 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文