PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu May 28, 2020 1:21 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Oct 23, 2010 1:49 pm 
Offline
Site Admin
User avatar

Joined: Tue Dec 23, 2003 3:10 am
Posts: 11470
Location: Toronto
When working with the Zend_Db, does anyone know if there is a way to select ambigious column names between tables, without having to explicitely use alias or prioritize column selection.

I.e.,

SELECT *
FROM table1
INNER JOIN table2 ON table1.fkid =table2.pkid

If both columns had a "foobar", the latter table would be the one to return it's foobar column value. Preferably, what I would like to see is, when I pass it a wildcard, it would do some magic and auto expand to, lets say

SELECT table1.id, table1.foobar
table2.id, table2.foobar
...

and return the values grouped by their table.

Now I realize this is probably a design decision, however, having come from CakePHP, and this is how they do it, I would like to expand this functionality into ZF.

Any ideas?


Top
 Profile  
 
PostPosted: Sat Oct 23, 2010 2:19 pm 
Offline
DevNet Master
User avatar

Joined: Fri Jan 18, 2008 1:36 am
Posts: 3549
Location: Israel, ME
There is no way to do this magically in ZF. It does split the wildcards per each table in the query, so you get table1.*,table2.* and so forth, so you can specify the columns for only one of the tables if you really need it.
As a general principle, I try to avoid wildcards and select columns by their names.


Top
 Profile  
 
PostPosted: Sat Oct 23, 2010 2:23 pm 
Offline
Site Admin
User avatar

Joined: Tue Dec 23, 2003 3:10 am
Posts: 11470
Location: Toronto


Top
 Profile  
 
PostPosted: Sat Oct 23, 2010 7:22 pm 
Offline
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
Just subclass & override protected function _tableCols() on Zend_Db_Select

Also relevant, describeTable() on Zend_Db_Adapter


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group