I'm using Doctrine 1.2. I'd like to execute a Doctrine_Query that, instead of returning a Doctrine_Collection will return a class of my choosing. That is, something like
$o = Doctrine_Query::create()
->fr开发者_JAVA百科om('Foo')
->execute();
$o; //instance of Doctrine_Collection
will normally return a generic Doctrine_Collection object. Instead I'd like it to return a Foo_Collection object, which I define elsewhere
class Foo_Collection extends Doctrine_Collection
{
public function soSomethingSpecificToAFooObject()
{
}
}
which will allow me to logically group functionality.
Is this possible? From my reading and poking at the code base this would seem to have something to do with hydrators, but I haven't been able to a manual page or tutorial that covers what I'm after.
Im pretty sure you can just add the following to your Record's setUp
or construct
methods (the table should be available in either one construct
is run before setUp
i think though):
$this->_table->setAttribute(Doctrine_Core::ATTR_COLLECTION_CLASS, 'Foo_Collection');
You can also set this globally on the Doctrine_Connection if you needed to extend Doctrine_Collection and use a different class throughout all models.
精彩评论