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?
[Zend] Selecting ambiguous column names
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: [Zend Framework] Selecting ambiguous column names
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.
As a general principle, I try to avoid wildcards and select columns by their names.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: [Zend Framework] Selecting ambiguous column names
I figured so. I haven't actually dug into the ZF code in quite some time, but I expect I should be able to override sometime to provide it meta data about the tables in question -- but what exactly is still to be determined.Eran wrote: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.
Mostly just curious if others have dealt with this as I've been working around this for quite some time. It's just annoiying when you have to split out 30 odd custom alias in a query.
Re: [Zend Framework] Selecting ambiguous column names
Just subclass & override protected function _tableCols() on Zend_Db_Select
Also relevant, describeTable() on Zend_Db_Adapter
Also relevant, describeTable() on Zend_Db_Adapter