Search code examples
phplithium

Lithium Relations namespaces bug?


My folder/namespace hierarchy:

  • app/models/entities
    • Entities.php
    • people
      • People.php
      • (other models)

I followed the instructions per this question: lithium fill multiple models from view, but got an error "failed to open stream: No such file or directory in C:\xampp\htdocs\PhiCRM\libraries\lithium\core\Libraries.php on line 468", which, yea... cuz as you saw above, its nested in another folder, which is indicated in the configs array, shown below

My fix: I changed

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

to

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

and now the error goes away (changed the second line, from 'People' to 'people\People'), but now I get the error: 'Related model class 'app\models\entities\people\people\People' not found.' in C:\xampp\htdocs\PhiCRM\libraries\lithium\data\model\Relationship.php on line 159, so now its tacking on ANOTHER people to the path string.

My question: Is this intended behavior? Shouldn't the relationships model use the class path I provided in the $configs array instead of string concatenation with the class name? If its a bug, should I report it, and how?


Solution

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

    Should work better with 'to' instead of 'class' ;-)