public function fetch($return = self::RETURN_COLLECTION) {
        /** We replace Post.xx by post.xx */
        foreach ($this->_entities as $entity) {
            $class = $this->_getTableEntity($entity);

            if ($entity != $class->name()) {
                $this->_query = preg_replace('#(.*)' . $entity . '\.(.*)#isU', '$1' . $class->name() . '.$2', $this->_query);
            }
        }

        /** Query execution */
        $sql = new Sql();
        $sql->vars($this->_vars);
        $sql->query('orm-' . $this->_token, $this->_query);

        if ($this->_type == self::QUERY_COUNT) {
            return $sql->fetch('orm-' . $this->_token, Sql::PARAM_FETCHCOLUMN);
        }
        else {
            $sql->fetch('orm-' . $this->_token, Sql::PARAM_FETCH);
        }

        $collection = $sql->data($this->_getEntityName($this->_entity->name()));

        /** We can do SELECT OR SELECT DISTINCT OR SELECT RAW */
        if (in_array($this->_type, [self::QUERY_DISTINCT, self::QUERY_RAW])) {
            $nLines = $collection->count();
            $in = '';

            /** @var $value \Gcs\Framework\Core\Orm\Entity\Entity */
            foreach ($collection as $key => $value) {
                $in .= $value->fields()[$value->primary()]->value;

                if ($key < $nLines - 1) {
                    $in .= ', ';
                }
            }

            $builder = new Builder($this->_entity);
            $collection = $builder->find()->where($this->_entity->name() . '.' . $this->_entity->primary() . ' IN (' . $in . ')')->fetch();
        }

        /** If we have fields with a relation ONE TO MANY OR MANY TO MANY */
        foreach ($this->_entity->fields() as $field) {
            if ($field->foreign != null && in_array($field->foreign->type(), [ForeignKey::ONE_TO_MANY, ForeignKey::MANY_TO_MANY])) {
                /** we loop through the results to add each time */
                switch ($field->foreign->type()) {
                    case ForeignKey::ONE_TO_MANY :
                        $collection = $this->_dataOneToMany($field, $collection);
                        break;

                    case ForeignKey::MANY_TO_MANY :
                        $collection = $this->_dataManyToMany($field, $collection);
                        break;
                }
            }
        }

        if ($return == self::RETURN_ENTITY && $collection->count() <= 1) {
            return $collection->first();
        }
        else {
            return $collection;
        }
    }