laurent
laurent

Reputation: 90776

Kohana ORM reports that record is not loaded when it is loaded

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?

Upvotes: 2

Views: 1415

Answers (2)

laurent
laurent

Reputation: 90776

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.

Upvotes: 5

alan
alan

Reputation: 241

How about 1st:

echo Debug::vars($this->request->query('session'), $session);

Upvotes: 0

Related Questions