2009年1月9日星期五

Re: [fw-core] Zend_DB_Select, fully re-build columns?

Are you trying to select only columns from the table "finders"? If so, you can pass in empty arrays as the 3rd argument to joinLeftUsing:

$select = $db->select();
$select->from('finders');
$select->joinLeftUsing('finder_images', 'finder_id', array());
$select->joinLeftUsing('professions', 'profession_id', array());
$select->where('finder_moderated = ?', 1);
$select->where('profession_rewrite = ?', $profession_rewrite);
$select->order('finder_image_path_preview DESC');
$select->order('finder_created_at DESC');
$select->limitPage($page, $per_page);


-Hector


On Fri, Jan 9, 2009 at 1:38 PM, Adam Blake <lluerssen@gmail.com> wrote:
Hi guys, using latest svn copy of ZF, i got trouble.

<?php

// ... require other code goes here ...

$profession_rewrite = 'dodo';

$select = $db->select();
$select->from('finders');
$select->joinLeftUsing('finder_images', 'finder_id');
$select->joinLeftUsing('professions', 'profession_id');
$select->where('finder_moderated = ?', 1);
$select->where('profession_rewrite = ?', $profession_rewrite);
$select->order('finder_image_path_preview DESC');
$select->order('finder_created_at DESC');
$select->limitPage($page, $per_page);

print $select;

?>

will return to me:

SELECT `finders`.*, `finder_images`.*, `professions`.* FROM `finders` LEFT JOIN `finder_images` ON `finder_images`.finder_id = `finders`.finder_id LEFT JOIN `professions` ON `professions`.profession_id = `finders`.profession_id WHERE (finder_moderated = 1) AND (profession_rewrite = 'other') ORDER BY `finder_image_path_preview` DESC, `finder_created_at` DESC LIMIT 20

how i can re-build it, into:

SELECT * ...

because, joined `finder_images` table rewrites `finder_id` of `finders` table.

没有评论: