为 Doctrine 指定与 YAML 的关系

发布于 2024-10-16 16:36:11 字数 1035 浏览 4 评论 0原文

只是尝试在 YAML 文件中为 Doctrine 指定一些表结构和模型。我正在浏览此页面上的文档: http://www.doctrine-project.org/projects/orm/1.2/docs/manual/yaml-schema-files/en

我还不太清楚 < 中的每一行是什么关系部分正在做。

以下是该页面中的一些示例 YAML:

User:
    columns:
    username:
      type: string(255)
    password:
      type: string(255)
    contact_id:
      type: integer
  relations:
    Contact:
      class: Contact
      local: contact_id
      foreign: id
      foreignAlias: User
      foreignType: one
      type: one

具体来说,关系,按顺序:

联系人 是.. 我猜测与此关系相关的其他对应表的名称?

类:联系是..到底是什么?将从此 YAML 创建的模型的名称?

local: contact_id 是本地密钥,我明白这一点。

foreign: id 是外键的字段名,我理解这个

foreignAlias: User 这一行是做什么的?

外国类型:一个
type: one: 我猜这两行一起指定了关系的类型,例如一对一?

感谢您的任何和所有帮助。

Just trying to specify some tables structures and models for Doctrine in a YAML file. I'm going through the documentation on this page: http://www.doctrine-project.org/projects/orm/1.2/docs/manual/yaml-schema-files/en

I haven't quite got a grasp on what each line in the relations section is doing.

Here's some sample YAML from that page:

User:
    columns:
    username:
      type: string(255)
    password:
      type: string(255)
    contact_id:
      type: integer
  relations:
    Contact:
      class: Contact
      local: contact_id
      foreign: id
      foreignAlias: User
      foreignType: one
      type: one

Specifically, relations, in order:

Contact is.. I am guessing the name of the other corresponding table pertaining to this relationship?

class: contact is.. what exactly? The name of the model that will be created from this YAML?

local: contact_id is the local key, I understand this.

foreign: id is the field name of the foreign key, I understand this

foreignAlias: User what is this line doing?

foreignType: one
type: one: I am guessing these two lines together specify the type of relationship, eg, one-to-one?

Thanks for any and all help.

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

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

发布评论

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

评论(1

伤感在游骋 2024-10-23 16:36:11

联系人是..我猜与此关系相关的其他对应表的名称?

没有。它是您稍后在访问用户的联系信息时使用的对象的名称。

$user->Contact->email

这可以与类名不同

class:联系方式是..到底是什么?将从此 >YAML?

创建的模型的名称

这就是您所引用的类。需要是 YAML 中的类名(即联系人)

local:contact_id是本地密钥,我明白这一点。
foreign:id是外键的字段名,我是这样理解的

foreignAlias:用户此行在做什么?

这是您可以从联系人对象访问用户信息的名称。

$联系人->用户->用户名

外国类型:一
type: one:我猜这两行一起指定了关系的类型,例如,>一对一?
杰普,你就在这里。

Contact is.. I am guessing the name of the other corresponding table pertaining to this >relationship?

Nope. It is the Name of the object you later use when accessing contact information of a user.

$user->Contact->email

This can be different from the Class-Name

class: contact is.. what exactly? The name of the model that will be created from this >YAML?

That is the class you are referencing. Needs to be the Classname in the YAML (i.e. Contact)

local: contact_id is the local key, I understand this.
foreign: id is the field name of the foreign key, I understand this

foreignAlias: User what is this line doing?

This is the name you can access the user information from a contact object.

$contact->User->username

foreignType: one
type: one: I am guessing these two lines together specify the type of relationship, eg, >one-to-one?
Jepp, you are right here.

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