sfPropelHelperPlugin - 0.8.0

This plugin makes it easier to do (non-default-)joins and hydrations.

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
sfPropelHelperPlugin 0.8.0alpha for sf 1.2 and Propel MIT
Plugin image
1
user
Sign-in
to change
your status

This plugin makes it easier to do (non-default-)joins and hydrations.

NOTE

PLEASE NOTE, THIS PLUGIN HAS BEEN DEPRECATED IN FAVOUR OF PROPEL1.5 AND THE sfPropelObjectPathBehaviorPlugin

Introduction

This plugin makes it easier to do non-default-joins. Instead of the limited doSelectJoin(xxx) Peer-Methods you are now free to do any join (between related tables, and with any depth) you desire and let the result get hydrated automatically.

This helper extends the functionality of Propel, while keeping it completely backwards compatible.

Example: imagine you have a Propel Photo and Album class, with this helper doing and hydrating all objects is perfomed like this:

$criteria = new Criteria();
$objectPaths = array('Photo', 'Photo.Album'); // this can be reduced to array('Photo.Album');

$criteria = addJoinsAndSelectColumns($criteria, $objectPaths);
$photos = hydrate($criteria, $objectPaths, $connection = null);

foreach ($photos as $photo)
{
  echo $photo->getAlbum()->getName()." -> ".$photo->getName()."<br>\n";
}

So called ObjectPaths have been introduced to define objects, with their relations. (Similar PropertyPaths have been introduced to define properties of (related)objects)

This code results in the following query:

SELECT Photo.ID, Photo.ALBUM_ID, Photo.NAME, Photo_Album.ID, Photo_Album.ALBUM_ID, Photo_Album.NAME FROM `photo` `Photo` LEFT JOIN album Photo_Album ON (Photo.ALBUM_ID=Photo_Album.ID)

Obviously the big advantage of this plugin shows when you have more complex join to be performed! The propel-model builder is extended to provide you with all the default joins. These get defined in the basePeer-classes like this (from the BasePhotoPeer):

static public function getRelations()
{
  return array (
    'Album' => array (
      'relatedClass' => 'Album',
      'oneToMany' => false,
      'associateMethod' => 'addPhoto',
      'leftKeys' => array (
        0 => PhotoPeer::ALBUM_ID,
      ),
      'rightKeys' => array (
        0 => AlbumPeer::ID,
      ),
      'joinType' => 'LEFT JOIN',
    ),
  );
}

You can extend this method in the Peer class and define custom relations from one class to the other.

Developers

Name Status Email
gravatar Leon van der Ree lead ln.nomed.em4nuf <<ta>> noeL

License

Show source

Copyright (c) 2009 Leon van der Ree

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.