UnionOfRAD/lithium — Issue #220: 'belongsto' Relationship breaks if related model is in a different namespace or folder
Author: tonyeung
Created: 2011-12-26 03:20:18+00:00
State: open

Fatal error: Uncaught exception 'lithium\core\ClassNotFoundException' with message 'Related model class 'app\models\entities\People' not found.' in C:\xampp\htdocs\PhiCRM\libraries\lithium\data\model\Relationship.php on line 159

in libraries\lithium\data\model\Relationship.php on line 115, changed

if (!$config['to']) {
$assoc = preg_replace("/\\w+$/", "", $config['from']) . $name;
$config['to'] = Libraries::locate('models', $assoc);
}

to

if (!$config['to']) {
if(!$config['class']){
$assoc = preg_replace("/\\w+$/", "", $config['from']) . $name;
}
else{
$assoc = $config['class'];
}
$config['to'] = Libraries::locate('models', $assoc);
}

my belongsto:

public $belongsTo = array(
'People' => array(
'class' => '\app\models\entities\people\People',
'key' => 'person_id',
),
);

my folder structure(mirrors namespaces)

* models
* entities
* Entities.php
* people
* People.php
* Employees.php
* organizations
* ...