2008年12月11日星期四

[fw-db] Index results by specific column name

Hey all,

I'm new to Zend_Db... converting from Doctrine. Doctrine had a cool
features [1] where you could indicate the column you want to index
your resulting array by. Is there any way to easily duplicate this in
Zend_Db?

Example:

CREATE TABLE User (id int, name varchar, phone varchar);
INSERT INTO User (1, 'Pete', '555-555-5555');
INSERT INTO User (2, 'George', '555-555-5555')
INSERT INTO User (3, 'Harry', '555-555-5555')

$q = Doctrine_Query::create();
$q->from('User u INDEXBY u.name');
$users = $q->execute(Doctrine::HYDRATE_ARRAY);

The resulting array would be like the following:

$users[1] = array('id' => 1, 'name' => 'Pete', 'phone' => '555-555-5555');
etc....

Thanks,
-=Dan

[1] http://www.doctrine-project.org/documentation/manual/1_0/en/dql-doctrine-query-language#indexby-keyword

没有评论: