1

Why am I getting this:

An error occurred

Application error

Exception information:

Message: Select query cannot join with another table

while trying to join two tables?

I have this line code inside my model which extends Zend_Db_Table_Abstract

public function getProjects() {
    $select = $this->select()
            ->from(array('sub' => $this))
            ->join(array('main' => 'main_projects'), 'main.mai_id = sub.mai_id');
    return $this->fetchAll($select);
}

And I use this in my controller: $this->view->entries = $this->sub_projects->getProjects();

Why the hell I get this error? I just want to make a simple join

SELECT sub.*, main.mai_title FROM sub_projects AS sub INNER JOIN main_projects AS main ON sub.mai_id = projects.mai_id;
enter code here
mechanical_meat
  • 163,903
  • 24
  • 228
  • 223
Rodrigo Souza
  • 7,162
  • 12
  • 41
  • 72

1 Answers1

1

I think here is your solution and explanation : http://www.mail-archive.com/fw-general@lists.zend.com/msg24553.html Another solution here : Translating a query to use Zend_Db_Select

Community
  • 1
  • 1
greg0ire
  • 22,714
  • 16
  • 72
  • 101
  • then I get: ` SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ccgss.object' doesn't exist` – Rodrigo Souza Sep 20 '10 at 18:47
  • Actually I also had to change `$this`for the name of the table – Rodrigo Souza Sep 20 '10 at 18:58
  • 1
    While this answer may theoretically answer the question, [it is better](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – hichris123 Feb 05 '14 at 19:29