protected function toEntityCollection($result)
    {
        switch (true) {

            // already a collection ?
            case is_object($result) && is_subclass_of($result, $this->collectionClass) :
                $collection = $result;
                break;

            // already a collection ?
            case $result instanceof Collection :
                $collection = new $this->collectionClass($result->toArray());
                break;

            // simple related entity ?
            case is_object($result) && is_subclass_of($result, $this->entityClass) :
                $collection = new $this->collectionClass(array($result));
                break;

            // simple array ?
            case is_array($result) :
                $collection = new $this->collectionClass($result);
                break;

            default:
                $collection = new $this->collectionClass();
                break;
        }

        if (is_callable(array($this, 'onLoad'))) {
            @trigger_error(
                sprintf('%s::onLoad() call is deprecated and will be removed in 2.0. Make "%s" invokable instead if you require to custom every "%s" loaded by ORM.',
                    static::class,
                    static::class,
                    $this->entityClass
                ),
                E_USER_DEPRECATED
            );

            return $this->onLoad($collection);
        }

        return $collection;
    }