0

所以我有2个模型。用户和组。每个组都有一个用户作为创建者,一个组有很多用户。这些表的 FK 设置正确,但我想知道是否有更简单的方法可以从其他对象获取所有相关的 FK 对象。例如,对于组对象,是否有内置方法来获取创建者的用户对象?或者对于用户,是否有内置方法来获取他所属的所有组对象?我无法通过 symfony 页面上的文档找到如何做到这一点。从我所见,我觉得我需要创建方法并使用教义来使用当前对象 id 访问适当的表等。

谢谢!

一些示例架构:

Group:
  actAs: { Timestampable: ~ }
  columns:
    name: { type: string(500), notnull: true }
    image: { type: string(255) }
    type: { type: string(255), notnull: true }
    created_by_id: { type: integer }
  relations: 
    User: { onDelete: SET NULL, class: User, local: created_by_id, foreign: id, foreignAlias: groups_created }
4

1 回答 1

4

您需要向我们展示您的代码以获得体面的答案,但它会如下所示。

YAML:

Group:
    columns:
        ..........
        creator_id:     { type: integer(4), notnull: true }
    relations:
        Creator:        { class: User, local: creator_id, foreign: id }

PHP:

$user = $group->getCreator();
于 2010-06-01T20:08:00.163 回答