2

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?

laurent
  • 88,262
  • 77
  • 290
  • 428

2 Answers2

5

After some digging into Kohana source code, I found out that the $loaded_ property was not set because my model use uuid instead id as a primary key. So I set it up in the model as protected $_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() returns false.

laurent
  • 88,262
  • 77
  • 290
  • 428
0

How about 1st:

echo Debug::vars($this->request->query('session'), $session);
matino
  • 17,199
  • 8
  • 49
  • 58
alan
  • 241
  • 2
  • 5