public function writeJoin($type, $targetType, $leftRight = 'LEFT')
{
if ($leftRight !== 'LEFT' && $leftRight !== 'RIGHT' && $leftRight !== 'INNER') {
throw new RedException('Invalid JOIN.');
}
$table = $this->esc($type);
$targetTable = $this->esc($targetType);
$field = $this->esc($targetType, TRUE);
return " {$leftRight} JOIN {$targetTable} ON {$targetTable}.id = {$table}.{$field}_id ";
}