【问题标题】:Custom Collections in Doctrine 1.2Doctrine 1.2 中的自定义集合
【发布时间】:2011-05-21 12:45:21
【问题描述】:

我正在使用 Doctrine 1.2。我想执行一个 Doctrine_Query ,而不是返回一个 Doctrine_Collection 将返回一个我选择的类。也就是说,像

$o = Doctrine_Query::create()
->from('Foo')
->execute();

$o; //instance of Doctrine_Collection

通常会返回一个通用的 Doctrine_Collection 对象。相反,我希望它返回一个我在别处定义的 Foo_Collection 对象

class Foo_Collection extends Doctrine_Collection
{

    public function soSomethingSpecificToAFooObject()
    {
    }
}

这将允许我对功能进行逻辑分组。

这可能吗?从我阅读和查看代码库来看,这似乎与水合器有关,但我无法找到涵盖我所追求的手册页或教程。

【问题讨论】:

    标签: php orm doctrine


    【解决方案1】:

    我很确定您可以将以下内容添加到 Record 的 setUpconstruct 方法中(我认为该表应该在 construct 之前运行的任一 setUp 中可用):

    $this->_table->setAttribute(Doctrine_Core::ATTR_COLLECTION_CLASS, 'Foo_Collection');
    

    如果您需要扩展 Doctrine_Collection 并在所有模型中使用不同的类,您也可以在 Doctrine_Connection 上全局设置。

    【讨论】:

    • 添加到 setUp 方法对我有用。感谢你们俩 - 非常有帮助。
    猜你喜欢
    • 2011-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-09
    • 1970-01-01
    相关资源
    最近更新 更多