【问题标题】:Kohana 3.2 relationship - JoinsKohana 3.2 关系 - 加入
【发布时间】:2012-06-05 17:43:45
【问题描述】:

我在 mysql 中有当前的设计:

表格文件主题

Kohana 有没有办法以某种方式建立关系,如果我做出类似的事情

ORM::factory('filesubject')->where('file_id','=',$file->id)->find_all()->as_array());

我从其他表中获取所有联接?

【问题讨论】:

    标签: kohana kohana-orm kohana-3.2 kohana-db


    【解决方案1】:

    我不确定你的问题。要自动加入模型,首先设置您的关系($_belongs_to 等),然后查看:

    在您的模型中:

    ORM property: $_load_with. eg: protected $_load_with= array(model1, model2, etc)
    

    或者在运行时:

    ORM method: with(). eg: ORM::factory('filesubject')->with('model')->with('model2')->find_all()
    

    我不认为 as_array() 函数会提取连接的数据。一旦它实际执行连接,您需要覆盖 as_array (或编写您自己的函数)以从连接的属性中输出嵌套的键/对值。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多