【问题标题】:How to do friend ORM model in fuelphp如何在fuelphp中做朋友ORM模型
【发布时间】:2014-03-23 18:21:28
【问题描述】:

我需要在fuelphp orm 模型中建立一个自引用多对多关系。 在应用程序中,用户可以将其他用户作为朋友。

我有一个用户表和朋友表。 users表存储用户的主要信息,friends表单行存储两个用户的关系。

Friends 表有字段 |编号 | user_id1 | user_id2 |.

我完全坚持如何在用户上创建多对多关系自引用。

这里是fuelphp orm 关系文档:http://fuelphp.com/docs/packages/orm/relations/many_many.html

谁能帮我解决这个问题?

【问题讨论】:

    标签: many-to-many fuelphp self-reference


    【解决方案1】:

    您只需在 $_many_many 属性中指定两个关系。

    protected static $_many_many = array(
        'children' => array(
            'key_from' => 'id',
            'key_through_from' => 'parent_id',
            'table_through' => 'my_relation_table',
            'key_through_to' => 'child_id',
            'model_to' => 'Model_User',
            'key_to' => 'id',
        ),
        'parents' => array(
            'key_from' => 'id',
            'key_through_from' => 'child_id',
            'table_through' => 'my_relation_table',
            'key_through_to' => 'parent_id',
            'model_to' => 'Model_User',
            'key_to' => 'id',
        ),
    );
    

    请注意,key_through_fromkey_through_to 在每个关系定义中都是翻转的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-28
      • 2012-04-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多