Download the PHP package negromovich/doctrine-relations-loader without Composer

On this page you can find all versions of the php package negromovich/doctrine-relations-loader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package doctrine-relations-loader

Doctrine Relations Loader

The library is a single class that allows you to load many related entities in an optimal way and performance.

Doctrine UnitOfWork's identityMap used for loading. So method "clear" in UnitOfWork breaks loading.

Usage

Use blog structure with users, posts, comments and likes for example.

/** @ORM\Entity() */
class User
{
    /**
     * @ORM\Id()
     * @ORM\Column(type="integer")
     */
    public $id;

    /** @ORM\Column(type="string") */
    public $name;

    /** @ORM\Column(type="string") */
    public $country;

    /** @ORM\OneToMany(targetEntity="Post", mappedBy="user") */
    public $posts;
}

/** @ORM\Entity() */
class Post
{
    /**
     * @ORM\Id()
     * @ORM\Column(type="integer")
     */
    public $id;

    /** @ORM\Column(type="string") */
    public $title;

    /** @ORM\Column(type="string") */
    public $content;

    /**
     * @ORM\ManyToOne(targetEntity="User")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
     */
    public $user;

    /** @ORM\OneToMany(targetEntity="Comment", mappedBy="post") */
    public $comments;

    /** @ORM\OneToMany(targetEntity="Like", mappedBy="post") */
    public $likes;
}

/** @ORM\Entity() */
class Comment
{
    /**
     * @ORM\Id()
     * @ORM\Column(type="integer")
     */
    public $id;

    /** @ORM\Column(type="string") */
    public $content;

    /**
     * @ORM\ManyToOne(targetEntity="Post")
     * @ORM\JoinColumn(name="post_id", referencedColumnName="id")
     */
    public $post;

    /**
     * @ORM\ManyToOne(targetEntity="User")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
     */
    public $user;
}

/**
 * @ORM\Entity()
 * @ORM\Table(name="`like`")
 */
class Like
{
    /**
     * @ORM\Id()
     * @ORM\Column(type="integer")
     */
    public $id;

    /**
     * @ORM\ManyToOne(targetEntity="Post")
     * @ORM\JoinColumn(name="post_id", referencedColumnName="id")
     */
    public $post;

    /**
     * @ORM\ManyToOne(targetEntity="User")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
     */
    public $user;
}

Now we count the number of countries from which we put Like for a specific user (just for example, it is better to use the calculation in the database).

$countries = [];
$user = $this->em->getRepository(User::class)->find(1);
foreach ($user->posts as $post) {
    foreach ($post->likes as $like) {
        $countries[$like->user->country] = 1;
    }
}
$num = count($countries);

By default, you will perform the number of queries to the database = number of posts + number of users + 2:

SELECT * FROM user WHERE id = 1;
SELECT * FROM post WHERE user_id = 1;
SELECT * FROM `like` WHERE post_id = ?; # for each post
SELECT * FROM user WHERE id = ?; # for unique user

Queries quantity is too large. I want to merge identical queries to the same table:

SELECT * FROM `like` WHERE post_id IN (?); # for all post
SELECT * FROM user WHERE id IN (?); # for all unique users

You can use eager loading, but it does not work with a large cascade of entities. Another way to use RelationsLoader from this library.

$countries = [];
$user = $this->em->getRepository(User::class)->find(1);

$relationsLoader = new RelationsLoader($this->em);
$relationsLoader->load($user, ['posts' => ['likes' => ['user']]]);

foreach ($user->posts as $post) {
    foreach ($post->likes as $like) {
        $countries[$like->user->country] = 1;
    }
}
$num = count($countries);

In this case, 4 queries to the database will be executed.

Syntax

In RelationsLoader::load, you must pass the data for which you want to load the relations (entity, array of entities, collection) and a hierarchical list of relationships to load. How is formed a hierarchical list of consider examples.


All versions of doctrine-relations-loader with dependencies

PHP Build Version
Package Version
Requires php Version ^5.5|^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package negromovich/doctrine-relations-loader contains the following files

Loading the files please wait ....