交响乐 +学说一对多关系

发布于 2024-08-23 12:10:57 字数 637 浏览 5 评论 0原文

我的 sf 1.4 + 学说 1.2 项目需要一对多关系。 我像这样复制了关系:

User:
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    contact_id:
      type: integer(4)
    username:
      type: string(255)
    password:
      type: string(255)

Phonenumber:
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    name:
      type: string(255)
    user_id:
      type: integer(4)
  relations:
    User:
      foreignAlias: Phonenumbers

然后,我重建我的架构,并为用户和电话号码生成后端模块。

在电话号码管理面板中,我可以通过用户选择框来设置用户。 但在用户管理面板中,我没有包含电话号码的列表,以允许用户为用户选择多个电话号码。 我如何在这里添加许多关系?

I need a one-to-many relationships for my sf 1.4 + doctrine 1.2 project.
I copied the relation just like this:

User:
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    contact_id:
      type: integer(4)
    username:
      type: string(255)
    password:
      type: string(255)

Phonenumber:
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    name:
      type: string(255)
    user_id:
      type: integer(4)
  relations:
    User:
      foreignAlias: Phonenumbers

Then, I rebuild my schema, and generate the backend modules for User and Phonenumber.

In the Phonenumber admin panel, I can set the user by a select box with Users.
But in the User admin panel I do not have a list with the phonenumbers to allow users to select multiple phonenumbers to the user.
How can I add the many relation here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

夕嗳→ 2024-08-30 12:10:57

我更喜欢这样做,因为您的用户可能有很多关系而不是电话号码,因此这将所有内容都放在一个地方......

在您的用户中:

relations:
   Phonenumber:
     class: Phonenumber  // model name for relation
     local: id           // key in this table
     foreign: id         // key in the referenced table
     type: many          // User has MANY phonenumbers
     foreignType: one    // Phonenumber has ONE user
     alias: Phonenumber  // What a user calls Phonenumber
     foreignAlias: User  // What a Phonenumber calls User

鉴于您是声明两个表的“id”而不是让 Doctrine 自动创建它们,您可能需要包含“本地”和“外部”...尚未测试。

I prefer to do it this way round as it's likely that your user will have many relations and not phonenumbers, so this keeps it all in one place....

In your User:

relations:
   Phonenumber:
     class: Phonenumber  // model name for relation
     local: id           // key in this table
     foreign: id         // key in the referenced table
     type: many          // User has MANY phonenumbers
     foreignType: one    // Phonenumber has ONE user
     alias: Phonenumber  // What a user calls Phonenumber
     foreignAlias: User  // What a Phonenumber calls User

Given that you're declaring the "id" for both tables instead of allowing Doctrine to create them automatically, you may need to include the "local" and "foreign"... havent tested.

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