ZF-7808: Missing or incorrect aliases for columns in 'intersectionTable' and 'matchTable' when using findManyToManyRowset() method

Issue Type: Bug Created: 2009-09-09T04:38:46.000+0000 Last Updated: 2012-11-20T20:52:44.000+0000 Status: Closed Fix version(s): Reporter: Webdevilopers (tridem) Assignee: None Tags: - Zend_Db_Table

Related issues: Attachments:


I have 3 models named Article, Category, ArticleCategories extending Zend_Db_Table_Abstract. The Article and the Category Model override the select() Method by adding a condition. This condition includes a column named 'deleted' in both db tables which causes the major problem.

This is the working sql query without the conditions: 'SELECT categories.categories_id, categories.categories_name, categories.categories_description, i.*, m.* FROM categories INNER JOIN categories2articles AS i INNER JOIN articles AS m ON i.articles_id = m.articles_id WHERE (i.categories_id = 1)'

By adding the condition I get: 'Zend_Db_Statement_Mysqli_Exception' with message 'Mysqli prepare error: Column 'deleted' in where clause is ambiguous'

This is, of course, a normal behaviour, since both sql strings for the conditions are the same, nameley: 'AND deleted IS NULL'.

Initially I try specify the columns. F.e. by adding the db table names as aliases which leads me to:

'AND categories.deleted IS NULL' // $select->where($this->_name . '.deleted ?', new Zend_Db_Expr('IS NULL')); and 'AND articles.deleted IS NULL' // $select->where($this->_name . '.deleted ?', new Zend_Db_Expr('IS NULL'));

The problem remains since the findManyToManyRowset() method creates its own aliases 'i' for '$intersectionTable' and 'm' for '$matchTable'.

I could hardcode these aliases in the models select() methods by: $select->where('m.deleted ?', new Zend_Db_Expr('IS NULL')); $select->where('i.deleted ?', new Zend_Db_Expr('IS NULL'));

But this will obviously cause problems with my table abstraction sooner or later.

Shouldn't the method simply add the correct columns to the correct aliases when calling the models table definition / override select() method?

fetchAll(); /\*\* \* @return 'Zend\_Db\_Statement\_Mysqli\_Exception' with message 'Mysqli prepare error: Column 'deleted' in where clause is ambiguous' \*/ foreach ($categoriesRowset as $categoryRow) { $articlesRowset = $categoryRow->findManyToManyRowset('Article', 'ArticleCategories', null, null ); } ?> array( 'columns' => 'articles\_id', 'refTableClass' => 'ArticleCategories', 'refColumns' => 'categories\_id' ) ); public function select() { $select = parent::select(); $select ->where('deleted ?', new Zend\_Db\_Expr('IS NULL')) ; /\*\* \* @return SELECT `articles`.\* FROM `articles` WHERE (deleted IS NULL) \*/ return $select; } } ?> from('categories', array( 'categories\_id', 'categories\_name', 'categories\_description' )) ->where('deleted ?', new Zend\_Db\_Expr('IS NULL')) ; /\*\* \* @return SELECT `categories`.`categories\_id`, `categories`.`categories\_name`, `categories`.`categories\_description` FROM `categories` WHERE (deleted IS NULL) \*/ return $select; } ?> array( 'columns' => 'articles\_id', 'refTableClass' => 'Article', 'refColumns' => 'articles\_id' ), 'Category' => array( 'columns' => 'categories\_id', 'refTableClass' => 'Category', 'refColumns' => 'categories\_id' ) ); ?>


Posted by Rob Allen (rob) on 2012-11-20T20:52:44.000+0000

Bulk change of all issues last updated before 1st January 2010 as "Won't Fix".

Feel free to re-open and provide a patch if you want to fix this issue.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.