public function &setJoinTable($table_name, $join_field = null)
    {
        $this->join_table = $table_name;

        if (empty($this->target_join_field)) {
            if (is_string($join_field) && $join_field) {
                $this->setTargetJoinField($join_field);
            } elseif (is_array($join_field)) {
                if (count($join_field) == 2 && !empty($join_field[0]) && !empty($join_field[1])) {
                    $this->setSourceJoinField($join_field[0]);
                    $this->setTargetJoinField($join_field[1]);
                } else {
                    throw new InvalidArgumentException('Join field should be an array with two elements');
                }
            } else {
                $registered_type = $this->getRegisteredType();

                if (($pos = strrpos($registered_type, '\\')) !== false) {
                    $this->target_join_field = Inflector::singularize(Inflector::tableize(substr($registered_type, $pos + 1))) . '_id';
                } else {
                    $this->target_join_field = Inflector::singularize(Inflector::tableize($registered_type)) . '_id';
                }
            }
        }

        return $this;
    }