public function getForeignValue($value, $method = '__toString')
 {
     if (ncChangeLogConfigHandler::getForeignValues() && $this->isForeignKey()) {
         $peerClassName = constant($this->adapter->getClassName() . '::PEER');
         $tableMap = call_user_func(array($peerClassName, 'getTableMap'));
         $column = $tableMap->getColumn($this->getFieldName());
         $relatedTableName = $column->getRelatedTableName();
         $relatedPeerClassName = ncClassFinder::getInstance()->findPeerClassName($relatedTableName);
         if (!is_null($relatedPeerClassName) && class_exists($relatedPeerClassName)) {
             $object = call_user_func(array($relatedPeerClassName, 'retrieveByPk'), $value);
             if (!is_null($object) && method_exists($object, $method)) {
                 return $object->{$method}();
             }
         }
     }
     return $value;
 }
 /**
  * This methods inspects the columns of the object's table and if one of them if a foreign key,
  * it returns the change log of the referenced object IF it points to the specified object (parameter).
  *
  * @param mixed $object
  * @param date $from_date
  * @param transformToAdapters
  *
  * @return Array of ncChangeLogEntry
  */
 public function getNNRelatedChangeLog($object, $from_date = null, $transformToAdapters = true)
 {
     $relatedChangeLog = array();
     $relatedObjects = array();
     if (!is_null($object)) {
         // Obtain object's information
         $object_class = get_class($object);
         $peer = constant($object_class . '::PEER');
         // Get all tableMaps and make the queries to retrieve all object instances that reference the object!!!
         ncClassFinder::getInstance()->reloadClasses();
         foreach (ncClassFinder::getInstance()->getPeerClasses() as $class => $path) {
             if ($class != get_class($object) && class_exists($class) && method_exists($class, 'getTableMap')) {
                 $criteria = new Criteria();
                 $tableMap = call_user_func(array($class, 'getTableMap'));
                 foreach ($tableMap->getColumns() as $c) {
                     if ($c->isForeignKey()) {
                         $method = 'get' . $c->getPhpName();
                         $relatedTableName = $c->getRelatedTableName();
                         $relatedColName = $c->getRelatedColumnName();
                         $relatedPeerClass = ncClassFinder::getInstance()->findPeerClassName($relatedTableName);
                         $relatedClass = ncClassFinder::getInstance()->findClassName($relatedTableName, $relatedPeerClass);
                         // Traverse all collumns. If any has as its `relatedClass` the class of $object, make a
                         // Criteria object to fetch every related object.
                         if ($relatedClass == get_class($object)) {
                             $criterion = $criteria->getNewCriterion(constant($class . '::' . $c->getName()), $object->getPrimaryKey());
                             $criteria->addOr($criterion);
                         }
                     }
                 }
                 if ($criteria->size() > 0) {
                     $relatedObjects[$class] = call_user_func(array($class, 'doSelect'), $criteria);
                 }
             }
         }
         // Get every object's change log
         foreach ($relatedObjects as $tableName => $objects) {
             foreach ($objects as $o) {
                 $criteria = new Criteria();
                 if (!is_null($from_date)) {
                     $criteria->add(ncChangeLogEntryPeer::CREATED_AT, $from_date, Criteria::GREATER_THAN);
                 }
                 if (sfMixer::getCallable('Base' . get_class($o) . ':getChangeLog') && count($changes = $o->getChangeLog($criteria)) > 0) {
                     if (method_exists($o, '__toString')) {
                         $relatedChangeLog[$tableName][strval($o)] = $changes;
                     } else {
                         $relatedChangeLog[$tableName][$o->getPrimaryKey()] = $changes;
                     }
                 }
             }
         }
     }
     return $relatedChangeLog;
 }