public function __call($method, $args)
{
static $stack = array();
$results = call_user_func_array(array($this->getSourceRecord(), $method), $args);
$validArray = is_array($results) && count($results) > 0;
if ($validArray || $results instanceof \ArrayAccess || $results instanceof TActiveRecord) {
$this->collectForeignObjects($results);
while ($obj = array_pop($stack)) {
$obj->collectForeignObjects($results);
}
} else {
if ($results instanceof TActiveRecordRelation) {
$stack[] = $this;
} else {
if ($results === null || !$validArray) {
$stack = array();
}
}
}
return $results;
}