Bogdan
Bogdan

Reputation: 1911

Zend SQL using string in join condition

I want to have a join like this:

$sql = new Sql($this->adapter);
$select = $sql->select();
$select->from(array('E' => 'Emails'));
$emailField = 
$select->join(array('F' => 'EntityFiles'), "F.RelatedEntityId = E.EmailId AND F.RelatedEntityType = 'email'", array('FileName' => 'Name'), $select::JOIN_LEFT);

But when I try to run it I get an error saying Unknown column '"email"' in 'on clause'. How can I get it to work?

Upvotes: 1

Views: 225

Answers (1)

BADAOUI Mohamed
BADAOUI Mohamed

Reputation: 2214

The second argument of the join method is the ON clause. So you have to set only the relation between your entities in this ON clause

You want to filter your results on this condition F.RelatedEntityType = 'email'.

Filtering must be in a WHERE clause. So just add a where clause with this condition.

Hope this helps.

Mohamed.

Upvotes: 1

Related Questions