Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-10-2007, 12:35 PM
Junior Member
 
Join Date: Aug 2007
Posts: 2
Default Zend_DB_Table and relational algebra

Hi,

1. is there any possibility to do
SELECT foo FROM bar
using Zend_DB_Table
PHP Code:
$bar->find() 
or
PHP Code:
$bar->fetchAll() 
result in SELECT * FROM bar - ok, but contains to much data

2. is there any possibility to do
SELECT * FROM foo F JOIN bar B ON F.id = B.f_key
using Zend_DB_Table
i`m not interested in solutions like
PHP Code:
$items $bar->fetchAll();
foreach (
$bar as $bar_item){
$tmp $bar_item->getParentRow();
//and do something

it produces too much SQL queries, while 1 is enough

please help me

Last edited by G3LO : 08-10-2007 at 12:36 PM. Reason: i found code confusing
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-14-2007, 02:13 PM
Junior Member
 
Join Date: Jul 2007
Location: Brisbane, Australia
Posts: 9
Default

From your example, I assume "$bar" is the table (a child of Zend_Db_Table_Abstract). If so, you can use "select" function (returns a Zend_Db_Select object) of the tables adapter (Zend_Db_Adapter_Abstract) to construct the join you're after.

eg.
PHP Code:
$adapter $bar->getAdapter();

$select $adapter()->select()
        ->
from(array('F''foo'))
        ->
join(array('B''bar'), 'F.id = B.f_key')

// get data
$adapter()->query($select)->fetchAll(); 
That's just rough and untested, but I think it's right.
There's much more info on the select object in the Reference Guide anyway.
__________________
Brenton Alker
Brisbane, Australia

http://blog.tekerson.com/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:28 PM.