I’m having a problem with the loaded() function of the Kohana ORM. I’m loading a record, and the record is definitely loaded since I can access its properties. However, the loaded() function returns false. Below is the code I’m using:
$sessionUuid = $this->request->query('session');
$session = ORM::factory('session')->where('uuid', '=', $sessionUuid)->find();
if (!$session->loaded()) {
echo "NOT LOADED: " . $session->user_id . "\n";
return;
}
The code below would output for example:
NOT LOADED: 5435
5435 being the correct user number, which shows that the record is in fact loaded. Does anybody know what could be causing this issue?
After some digging into Kohana source code, I found out that the
$loaded_property was not set because my model useuuidinsteadidas a primary key. So I set it up in the model asprotected $_primary_key = 'uuid'and now it’s working.This seems like a bug in Kohana though because the primary key is not relevant for this query. Also the model is indeed loaded so it seems odd that
loaded()returnsfalse.