PHP code example of craftyshadow / propel-equalnest-behavior

1. Go to this page and download the library: Download craftyshadow/propel-equalnest-behavior library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

craftyshadow / propel-equalnest-behavior example snippets




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

$john->addFriend($peter);
$john->addFriend($marry);
$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->removeFriends();
$john->getFriends(); // empty array
$john->save(); // commit to the DB


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



$person->addFriend($friend);

$person->hasFriend($friend);

// 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
$person->setFriends($friends_array);

// append to the current collection of friends
$person->addFriends($friends_array);

// remove a specfic friend
$person->removeFriend($friend)

// remove all friends
$person->removeFriends();

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



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

PersonQuery::create()->countFriendsOf($person, $con = null);
ini
; 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