This behavior provides a way to define relations between objects that have equal hierarchy (friendship).

1.2.0 2014-12-05 23:31 UTC

This package is not auto-updated.

Last update: 2022-11-26 04:34:25 UTC


Build Status

The EqualNestBehavior is inspired by Doctrine's Equal Nest Relations implementation, and provides a way to define relations between objects that have equal hierarchy - think about a person and his friends.


This behavior requires Propel >= 1.6.0.


Get the code by cloning this repository, or by using Composer (recommended):

    "require": {
        "craftyshadow/propel-equalnest-behavior": "~1.2"

Then, if you don't use Composer, or an autoloader in your application, add the following configuration to your or propel.ini file:

propel.behavior.equal_nest.class = vendor.craftyshadow.propel-equalnest-behavior.src.EqualNestBehavior

Note: vendor.craftyshadow.propel-equalnest-behavior.src.EqualNestBehavior is the path to access the EqualNestBehavior class in "dot-path" notation.

Then declare the behavior in your schema.xml:

<table name="person">
  <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
  <column name="name" type="VARCHAR" required="true" />

<table name="friend">
  <behavior name="equal_nest">
    <parameter name="parent_table" value="person" />
  <!-- you do not need to specify any colums for the "friend" table, the behavior will add them automatically -->

Setup with symfony 1.4

Copy the behavior to lib/vendor/equal_nest_behavior and then register the behavior class by adding the following to the bottom of the config/propel.ini file:

; check that you have behaviors enabled
propel.builder.addBehaviors = true

; and add the custom behavior
propel.behavior.equal_nest.class = lib.vendor.equal_nest_behavior.EqualNestBehavior

Then in your schema.yml:


    id: ~
    name: { type: varchar(255) }

      symfony: { form: false, filter: false }
        parent_table: person
    # you do not need to specify any columns for the "friend" table, the behavior will add them automatically


Continuing with the example above, here is how you would use the Person object to define Friend relationships:


$john  = new Person();
$peter = new Person();
$marry = new Person();

$john->addFriends(array($peter, $marry)); // same as the above

$john->getFriends(); // returns a PropelObjectCollection ($peter, $marry)

$john->hasFriend($peter); // true
$peter->hasFriend($john); // true

$john->getFriends(); // empty array
$john->save(); // commit to the DB

The most important thing to remember is that all changes are committed to the database only after you call the ->save() method!

Also, keep in mind that relations are non-transitional:

$john->hasFriend($peter); // false

If you need this you will have to manually implement it.

ActiveRecord API




// get all friends, will be cached if no citeria specified. Filtered by the criteria otherwize
$person->getFriends($criteria = null, $con = null);

// replace the current collection of friends

// append to the current collection of friends

// remove a specfic friend

// remove all friends

$person->countFriends($criteria = null, $distinct = false, $con = null);

ActiveQuery API


PersonQuery::create()->findFriendsOf($person, $con = null);

PersonQuery::create()->countFriendsOf($person, $con = null);


<behavior name="equal_nest">
    <parameter name="parent_table"       value="person" />
    <parameter name="reference_column_1" value="friend_1" />
    <parameter name="reference_column_2" value="friend_2" />

Propel pluralizer

This behavior makes use of the Propel pluralizer when generating the relational interface. Make sure to always use the StandardEnglishPluralizer bundled with Propel 1.6 and up whenever possible (eg when you are starting a new project).

To use the better pluralizer add the following to your (for standalone Propel) or propel.ini (for symfony + Propel):

propel.builder.pluralizer.class = builder.util.StandardEnglishPluralizer

Running tests

Install dependencies:

php composer.phar install --dev

Run the test suite:



This behavior is released under the MIT License. See the bundled LICENSE file for details.