为 Doctrine 指定与 YAML 的关系
只是尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有。它是您稍后在访问用户的联系信息时使用的对象的名称。
$user->Contact->email
这可以与类名不同
这就是您所引用的类。需要是 YAML 中的类名(即联系人)
这是您可以从联系人对象访问用户信息的名称。
$联系人->用户->用户名
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
That is the class you are referencing. Needs to be the Classname in the YAML (i.e. Contact)
This is the name you can access the user information from a contact object.
$contact->User->username