Question

Using Kohana 3, I have my User table with a field that references a field from another table in the database, however, I can't find where the user data is requested so I can add a ->with to it so I can use it throughout the site.

I'm still digging around and these are the pieces I've found so far:

in: modules/orm/classes/Kohana/Auth/ORM.php

public function get_user($default = NULL)

it calls parent::get_user($default); so when I look up it’s parent: modules/auth/classes/Kohana/Auth.php:74, it's running this:

return $this->_session->get($this->_config['session_key'], $default);

$this->_session is created using:

Session::instance($this->_config['session_type']);

which I tracked down to: system/classes/Kohana/Session.php.

I think I reached a dead-end there.


I also tried doing a search for ORM::factory('User'), however, it's only used on login as far as I can tell.

get_user() returns an object of Model_User, but I'm not quite sure how to work with that to help me out.

Was it helpful?

Solution 3

The problem was coming from the fact that when you login, the data is cached and not pulled again until you re-login. So the tables needed to be joined on the login methods.

OTHER TIPS

In modules/auth/classes/model/auth/user.php (phew) there's on line 86 in my possibly outdated Kohana 3 install:

// Attempt to load the user
$this->where($fieldname, '=', $array['username'])->find();

Given that Model_Auth_User extends ORM this seems to be where it queries the db for the user, and hopefully where you can add your requirements.

Maybe use _load_with and always load the other table together with the user?

class Model_User extends Model_Auth_User
{

    protected $_table_columns = array(
        'id' => '',
        'username' => '',
        'email' => '',
        'password' => '',
        'logins' => '',
        'last_login' => '',
        'some_id' => '',
    );

    protected $_belongs_to = array(
        'some_model' => array('foreign_key' => 'some_id'),
    );

    protected $_load_with = array(
        'some_model',
    );
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top