TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
Relationship over three Models
  • Hey,

    I have the following table structure:
    user
    pictures
    useronline

    and the following relations: user --- has_many pictures and user --- has_one useronline

    The Models look like this:

    - user -
    class Model_User extends Model_Auth_User {

    protected $_table_name = 'community_userdata';

    protected $_load_with = array('useronline');

    // Relationships
    protected $_has_many = array(
    'user_tokens' => array('model' => 'user_token'),
    'roles' => array('model' => 'role', 'through' => 'roles_users'),
    'pictures' => array('model' => 'picture')
    );
    }


    - pictures -
    class Model_Picture extends ORM {

    protected $_table_name = 'community_userdata_bilder';
    // Relationships
    protected $_belongs_to = array('u' => array('model' => 'user', 'foreign_key' => 'user_id'));
    protected $_load_with = array('u', 'u:useronline');
    }


    - useronline -
    class Model_Useronline extends ORM {

    protected $_table_name = 'community_useronline';
    // Relationships

    protected $_has_one = array('u' => array('model' => 'user'));

    }


    You can see in Model_Picture, I will join automatically with user and with useronline from user. (u:useronline). But if I use $result->u->useronline - kohana will load the user online data lazy too although the query will build correctly?

    How can I work with the useronline Object over Model_Picture without lazy load the data from the Model_User.

    Any Ideas?

    Kind regards
  • Looks like you're missing a relationship in your User model, shouldn't you have something like this?
    protected $_belongs_to = array('useronline');