Coder Social home page Coder Social logo

nextras / orm Goto Github PK

View Code? Open in Web Editor NEW
307.0 307.0 57.0 3.04 MB

Orm with clean object design, smart relationship loading and powerful collections.

Home Page: https://nextras.org/orm

License: MIT License

PHP 99.14% Shell 0.02% PLpgSQL 0.84%
database nextras object-relational-mapper orm php

orm's People

Contributors

adaamz avatar dependabot[bot] avatar hrach avatar jantvrdik avatar jehla avatar jkavalik avatar jtojnar avatar jzechy avatar kinaps avatar kuceramartin avatar mabar avatar martenb avatar matej21 avatar mikulas avatar milanpala avatar mlejnekpavel avatar ondrejmirtes avatar pavelkovar avatar pryznar avatar qwerin avatar radimvaculik avatar radmax avatar robskr avatar ste93cry avatar stpnkcrk avatar tomaswindsor avatar uestla avatar vaclavpavek avatar vitkutny avatar vyki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

orm's Issues

Normalize false result

  • Repository::getBy* returns FALSE on no result.
  • Everywhere else however null is provided (empty relationship in entity, etc).

What about returning NULL everywhere?

STI / Metadata name does not respect annotation with multiple entities

/**
 * @property OneHasMany|FacebookComment[] $comments    {1:m ContentsRepository $parent}
 */
class FacebookThread extends Orm\Entity\Entity {}

/**
 * @property ManyHasOne|FacebookThread[] $parent {m:1 ContentsRepository $comments}
 */
class FacebookComment extends Orm\Entity\Entity {}

class ContentsRepository extends Orm\Repository\Repository
{

    public static function getEntityClassNames()
    {
        return [
            FacebookComment::class,
            FacebookThread::class,
        ];
    }

    public function getEntityClassName(array $data = NULL)
    {
        if ($data === NULL)
        {
            return self::getEntityClassNames();
        }

        if (isset($data['type']) && class_exists($data['type']))
        {
            return $data['type'];
        }

        throw new InvalidStateException;
    }
}

Expected behaviour is that the comments is only mapped on FacebookThread which is specified in annotation. Instead it tries to map on all entities the repository manages, which fails on
Fitak\FacebookComment::$parent has not defined a symetric relationship in Fitak\FacebookComment::$comments.

CompositePK & getById()

filtering by Id when entity has composite key should automatically translate array param as argument for each part of composite key.

Final naming

Before 1.0 I would propably do some renames, which I would aware after releasing first stable version.

Namespaces:

  • Entity\Collection -> Collection
  • Relationships -> Entity\Relationships

Classes:

  • nothing at this time

Methods:

  • nothing at this time

Do you have any ideas to the suggested renames or new suggestions?

enum accepts value getter

Would be nice, if enum annotation would accept method name, which would returned the allowed values.

Schemed m:n joining table

Nextras\Orm\InvalidStateException: No primary keys detected for many has many 'contacts.contacts_x_contacts.tags' join table

Singularize destroy class name

Inflect::singularize($class) called in Repository::getEntityClassNames() destroy class name and AnnotationsParser throws ReflectionException #-1:

For example: Users, UsersRepository and UsersMapper not found because:

ReflectionException #-1 Class ORM\User does not exist

dump of $repositories:
secviceName => "orm.repositories.users",
name => "users",
entities => array("ORM\User"),
class => "ORM\UsersRepository"

Documentation

So. Yeah. Is there a documentation yet? If not, can I help documenting this lib? Is there a private draft or something? Since the 1.0 is in beta for quite a while now. I think it's somewhat past the time :)

On a related note (and I think I might have asked you earlier this fall), would you be interested in step by step manual for migrating from porm? If so, I would do that, but having a doc first would be great to prevent duplicated concept explanations.

Count of fetched & unfetched entities in Collection.

  • Currently, ICollection & IRelationshipCollection implements Countable.
  • ArrayCollection has already fetched entites, so count counts array length.
  • Collection always run sql query to get the count.

Would be nice to introduce API, which would allow to fetch entities and return the array count for Collection. Possibilities:

  1. Remove Countable interface and introduce optional (?) parameter, which will force the needed behaviour. NULL would probably means autodetect.
  2. Introduce new method(s). Eash method would have the exact meaning, name such as countFetched, countInStorage. We could let the Countable interface, or removed it either.
  3. Other possibility.

Personally, I would like to avoid method parameter, since it's much less usable in templates, etc. However, I have no great idea about methods naming. Any suggests? cc @JanTvrdik

Implement IdentityMap::refresh

In long-run processes it's quite commont we need to refetch actual state of entity in database. This api should be a little bit hidden in IdentityMap. refresh would refetch data and updated entity state. If entity isModified() === TRUE, exception should be thrown.

ToArrayConverter::toArray does not ommit relationships

ToArrayConverter::toArray should omit relationships when calling with type IEntity::TO_ARRAY_RELATIONSHIP_AS_IS, but it doesn't. Instead, the output array contains Entity, OneHasMany, etc. instances on relationship keys.

Traversing through filtered relationships

It would be nice to add api & possibility to filter & travers by filtered relationships. Such as

/**
 * @property      Comment[] $allComments {1:m CommentsRepository}
 * @property-read Comment[] $comments {filter $allComments}
 */
class Post extends Entity
{
    public function filterComments(ICollection $collection)
    {
        return $collection->findBy(['deletedAt' => NULL]);
    }
}

// find all posts which were commented by lord Stark
// and these comments weren't deleted.
$this->orm->posts->findBy(['this->comments->author' => $lordStark->id]);

Recursive removal

In adc3e94 was implemented recursive removal. Eg. removing author removes also books, since books can't exists without defined author.

I'm thinking, if it wouldn't be better to don't make this recursive remove by default. If it's denied to recursive remove, orm will try set NULL value, which will throws exception.

So, default false would be safer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.