2017 © Pedro Peláez
 

cakephp-plugin cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

image

chinpei215/cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

  • Saturday, January 20, 2018
  • by chinpei215
  • Repository
  • 5 Watchers
  • 6 Stars
  • 222 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 2 Open issues
  • 13 Versions
  • 17 % Grown

The README.md

Software License Build Status Coverage Status Scrutinizer, (*1)

EagerLoader Plugin for CakePHP 2.x

An eager loading beahavior plugin for CakePHP 2.x which is highly compatible to the Containable behavior but generates better queries., (*2)

Requirements

  • CakePHP 2.x
  • PHP 5.3+

Installation

See the How to Install Plugins in the CakePHP documentation for general help., (*3)

  • Put the EagerLoader directory into your plugin directory or install the plugin with Composer from the directory where your composer.json file is located:
php composer.phar require chinpei215/cakephp-eager-loader
  • Load the plugin in your app/Config/bootstrap.php file:
CakePlugin::load('EagerLoader');

php class Post extends AppModel { public $actsAs = array('EagerLoader.EagerLoader'); }, (*4)

Usage

$Comment->find('first', [
    'contain' => [
        'Article.User.Profile',
        'User.Profile',
    ]
]);

EagerLoaderBehavior has a high compatibility with ContainableBehavior, but generates better queries. In the above example, only 2 queries will be executed such as the following:, (*5)

SELECT
    Comment.id, ...
FROM
    comments AS Comment
    LEFT JOIN articles AS Article ON (Comment.article_id = Article.id)
    LEFT JOIN users AS User ON (Article.user_id = User.id)
    LEFT JOIN profiles AS Profile ON (User.id = Profile.user_id)
WHERE
    1 = 1

```sql SELECT User.id, ... FROM users AS User LEFT JOIN profiles AS Profile ON (User.id = Profile.user_id) WHERE User.id IN (1, 2, 3), (*6)

If using `ContainableBehavior`, how many queries are executed? 10 or more?

## Incompatibility problems

`EagerLoaderBehavior` returns almost same results as `ContainableBehavior`, however you might encounter incompatibility problems between the 2 behaviors.
For example `EagerLoaderBehavior::contain()` is not implemented yet.

Then disabling `EagerLoaderBehavior` on the fly, you can use `ContainableBehavior::contain()` instead:
```php
$Comment->Behaviors->disable('EagerLoader');
$Comment->Behaviors->load('Containable');
$Comment->contain('Article');
$result = $Comment->find('first');

For your information, EagerLoaderBehavior can be coexistent with ContainableBehavior., (*7)

$actsAs = [
    'EagerLoader.EagerLoader', // Requires higher priority than Containable
    'Containable'
]

Using this way, you need not to call load('Containable') in the above example., (*8)

The Versions

20/01 2018

dev-fix-cache-overflow

dev-fix-cache-overflow https://github.com/chinpei215/cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

  Sources   Download

MIT

The Requires

 

cakephp load contain eager containable

01/02 2017

dev-master

9999999-dev https://github.com/chinpei215/cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

  Sources   Download

MIT

The Requires

 

cakephp load contain eager containable

01/02 2017

dev-support-2.5

dev-support-2.5 https://github.com/chinpei215/cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

  Sources   Download

MIT

The Requires

 

cakephp load contain eager containable

01/02 2017

0.4.0

0.4.0.0 https://github.com/chinpei215/cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

  Sources   Download

MIT

The Requires

 

cakephp load contain eager containable

12/10 2016

0.3.4

0.3.4.0 https://github.com/chinpei215/cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

  Sources   Download

MIT

The Requires

 

cakephp load contain eager containable

09/09 2016

0.3.3

0.3.3.0 https://github.com/chinpei215/cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

  Sources   Download

MIT

The Requires

 

cakephp load contain eager containable

09/09 2016

dev-fix-issue19

dev-fix-issue19 https://github.com/chinpei215/cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

  Sources   Download

MIT

The Requires

 

cakephp load contain eager containable

17/03 2016

0.3.2

0.3.2.0 https://github.com/chinpei215/cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

  Sources   Download

MIT

The Requires

 

cakephp load contain eager containable

22/02 2016

dev-appveyor

dev-appveyor https://github.com/chinpei215/cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

  Sources   Download

MIT

The Requires

 

cakephp load contain eager containable

14/02 2016

0.3.1

0.3.1.0 https://github.com/chinpei215/cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

  Sources   Download

MIT

The Requires

 

cakephp load eager

13/02 2016

0.3.0

0.3.0.0 https://github.com/chinpei215/cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

  Sources   Download

MIT

The Requires

 

cakephp load eager

11/02 2016

0.2.0

0.2.0.0 https://github.com/chinpei215/cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

  Sources   Download

MIT

The Requires

 

cakephp load eager

11/01 2016

0.1.0

0.1.0.0 https://github.com/chinpei215/cakephp-eager-loader

CakePHP 2.x plugin to make it possible to eager load

  Sources   Download

MIT

The Requires

 

cakephp load eager