Download the PHP package yii2tech/ar-eagerjoin without Composer

On this page you can find all versions of the php package yii2tech/ar-eagerjoin. 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 ar-eagerjoin

ActiveRecord Eager Join Extension for Yii 2


This extension provides support for ActiveRecord relation eager loading via 'join' without extra query.

For license information check the LICENSE-file.

Latest Stable Version Total Downloads Build Status

Installation

The preferred way to install this extension is through composer.

Either run

or add

to the require section of your composer.json.

Usage

This extension provides support for ActiveRecord relation eager loading via 'join' without extra query. Imagine we have the following database structure:

If you need to display listing of items, with the groups they belong to, ordered by group name or code, you'll have to use JOIN SQL statement and thus - \yii\db\ActiveQuery::joinWith() method:

However, the code above will perform 2 SQL queries: one - for the item fetching (including JOIN and ORDER BY statements) and second - for the group fetching. While second query will be very simple and fast, it is still redundant and unefficient, since all group columns may be selected along with the item ones.

This extension provides [[yii2tech\ar\eagerjoin\EagerJoinTrait]] trait, which, once used in the ActiveRecord class, allows selecting related records without extra SQL query.

Setup example:

In order to populate related record though 'join' query, you'll need to manually append its columns into the SELECT query section and alias them by names in following format:

where:

For example:

Here 'groupname' column of the query result set is passed to $item->group->name, 'groupcode' - to $item->group->code and so on.

Heads up! Do not forget to disable eager loading, passing false as second argument of joinWith() method, otherwise you'll gain no benefit.

Note: choose boundary carefully: it should not be present as a part of the columns (or aliases), which are not meant to be passed to the related records. Thus double underscore ('__') is used as default.

Tip: if you use 'camelCase' notation for your table columns, you may use single underscore ('_') as a boundary in order to make select statements more clear.

You may speed up composition of the query for the eager join using [[\yii2tech\ar\eagerjoin\EagerJoinQueryTrait]] trait. This trait should be used in the [[\yii\db\ActiveQuery]] instance:

Then you'll be able to use eagerJoinWith() method while building a query:

Composition of the proper 'select' and 'join' statements will be performed automatically.

Restrictions and drawbacks

While reducing the number of executed queries, this extension has several restrictions and drawbacks.

1) Only 'has-one' relations are supported. Extension is unable to handle 'has-many' relations. You should use regular joinWith() and eager loading for 'has-many' relations.

2) If all selected related model fields will be null, the whole related record will be set to null. You should always select at least one 'not null' column to avoid inappropriate results.

3) Despite extra query removal, this extension may not actually increase overall performance. Regular Yii eager join query is very simple and fast, while this extension consumes extra memory and performs extra calculations. Thus in result performance remain almost the same. In most cases usage of this extension is a tradeoff: it reduces load on Database side, while increases it on PHP side.


All versions of ar-eagerjoin with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version ~2.0.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 yii2tech/ar-eagerjoin contains the following files

Loading the files please wait ....