Symfony 1.4 Propel:我定义了,但表中未定义外键

发布于 2024-12-27 11:45:49 字数 638 浏览 1 评论 0原文

让我们看看这个架构:

  orders:
    _attributes:    { phpName: Orders, default_table_charset: utf8, default_table_collate: utf8_general_ci }
    id:             ~
    category_id:    { type: integer, size: '10', required: true, defaultvalue: '0', foreigntable: categories, foreignreference: id }
    whatisthis:     { type: longvarchar, required: false }

  categories:
    _attributes: { phpName: Categories }
    id:          ~
    name:        { type: varchar, size: '255', required: true, defaultvalue: '' }
    _uniques:    { index_name: [name] }

我发现我的表中没有定义外键。我正在使用 innoDB,因此 PK 是可能的。或者 Propel 不应该设置外键?

Lets see this schema:

  orders:
    _attributes:    { phpName: Orders, default_table_charset: utf8, default_table_collate: utf8_general_ci }
    id:             ~
    category_id:    { type: integer, size: '10', required: true, defaultvalue: '0', foreigntable: categories, foreignreference: id }
    whatisthis:     { type: longvarchar, required: false }

  categories:
    _attributes: { phpName: Categories }
    id:          ~
    name:        { type: varchar, size: '255', required: true, defaultvalue: '' }
    _uniques:    { index_name: [name] }

I figured out that the foreign keys are not defined in my tables. Im using innoDB so PKs are possible. Or Propel isnt supposed to set foreign keys?

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

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

发布评论

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

评论(2

红焚 2025-01-03 11:45:49

foreingtable”和“foreignreference”应该采用驼峰式大小写。并且category_id'的大小应该等于类别id的大小。

  orders:
    _attributes:    { phpName: Orders, default_table_charset: utf8, default_table_collate: utf8_general_ci }
    id:             ~
    category_id:    { type: integer, size: '10', required: true, defaultvalue: '0', foreignTable: categories, foreignreRerence: id }
    whatisthis:     { type: longvarchar, required: false }

  categories:
    _attributes: { phpName: Categories }
    id:          ~
    name:        { type: varchar, size: '255', required: true, defaultvalue: '' }
    _uniques:    { index_name: [name] }

The "foreingtable" and "foreignreference" should be camel cased. And the category_id' size should be equal with the categories's id's size.

  orders:
    _attributes:    { phpName: Orders, default_table_charset: utf8, default_table_collate: utf8_general_ci }
    id:             ~
    category_id:    { type: integer, size: '10', required: true, defaultvalue: '0', foreignTable: categories, foreignreRerence: id }
    whatisthis:     { type: longvarchar, required: false }

  categories:
    _attributes: { phpName: Categories }
    id:          ~
    name:        { type: varchar, size: '255', required: true, defaultvalue: '' }
    _uniques:    { index_name: [name] }
绝不服输 2025-01-03 11:45:49

您使用的是哪个 symfony 和 propel 版本?

假设使用 Propel 1.x,这里是一个一对多关系示例:


  musician:
    _attributes: { phpName: Musician }
    id: { phpName: Id, type: INTEGER, size: '9', primaryKey: true, autoIncrement: true, required: true }
    #other fields
  musician_album:
    _attributes: { phpName: MusicianAlbum }
    id: { phpName: Id, type: INTEGER, size: '9', primaryKey: true, autoIncrement: true, required: true }
    musician_id: { phpName: MusicianId, type: INTEGER, size: '9', required: true, foreignTable: musician, foreignReference: id, onDelete: CASCADE, onUpdate: CASCADE }
    #other fields
    _indexes: { musician_id: [musician_id] }

说实话,我更喜欢手动创建数据库表(设置、索引、外键等),然后使用 symfony(假设您正在使用 Symfony 1.x) 任务来创建模式:

symfony propel:build-schema

Which symfony and propel version are you using?

Supposing that are using Propel 1.x, here you are a one-many relationship example:


  musician:
    _attributes: { phpName: Musician }
    id: { phpName: Id, type: INTEGER, size: '9', primaryKey: true, autoIncrement: true, required: true }
    #other fields
  musician_album:
    _attributes: { phpName: MusicianAlbum }
    id: { phpName: Id, type: INTEGER, size: '9', primaryKey: true, autoIncrement: true, required: true }
    musician_id: { phpName: MusicianId, type: INTEGER, size: '9', required: true, foreignTable: musician, foreignReference: id, onDelete: CASCADE, onUpdate: CASCADE }
    #other fields
    _indexes: { musician_id: [musician_id] }

To be honest, I prefer to manually create the database tables (setting, indexes, foreign keys and so on) and then I use the symfony (assuming that you are using Symfony 1.x) task to create the schema:

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