Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3346148
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:16:10+00:00 2026-05-18T01:16:10+00:00

I have the following tables: users { id, name } events { id, name

  • 0

I have the following tables:

users           { id, name }
events          { id, name }
user_events     { id, date, user_id, event_id }
user_summaries  { id, user_id, event_id, qty }

Table user_events stores all user events (there are many of the same types at different times) and user_summaries stores how many of each type of events occured to each user. The former gets only INSERT queries and the latter mostly UPDATE ones.

Of course both user_events and user_summaries have foreign keys to link with users and events tables.
I want to represent this relation in my Models in Kohana. I have experience with foreign keys, but it’s my first approach to both Kohana and ORM and I’m not sure really how to define my models there to represent these relations.

What I want to be able to do is basically this:

// I'm able to do this.
$user = ORM::factory('user', 1);
$user_events = $user->events->find_all();
$user_summaries = $user->usersummaries->find_all();

// I'm able to do this, too.
$event = ORM::factory('event', 1);
$event_users = $event->users->get_all();

// I don't know how to be able to do this:
$user_event = ORM::factory('userevent', 1);
$user_details = $user_event->user->find();
$event_details = $user_event->event->find();

My current models look like this:

# classes/model/user.php
class Model_User extends ORM
{
    protected $_has_many = array(
        'scores'    => array(),
        'usersummaries' => array(),
    );
}

# classes/model/event.php
class Model_Event extends ORM
{
    protected $_has_many = array(
        'scores'        => array(),
        'usersummaries' => array(),
    );
}

# classes/model/userevent.php
class Model_Userevent extends ORM
{
    protected $_belongs_to = array(
        'user'  => array(),
        'event' => array(),
    );
}

# classes/model/usersummary.php
class Model_Usersummary extends ORM
{
    protected $_belongs_to = array(
        'user'  => array(),
        'event' => array(),
    );
}

Currently calling:

$user_event = ORM::factory('userevent', 1);
$user_details = $user_event->user->find();

returns always the first user from users table, even though userevent has different user_id.
I presume I need to change something in Model_userevent but I’d use with some help.

NB. I’m using Kohana 3.0.8.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T01:16:10+00:00Added an answer on May 18, 2026 at 1:16 am

    Use $user_event->user (without find()). Models look fine, but may be you should manually define related models for usersummaries and userevents relations (Ko3 inflector may works wrong for these names)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following tables questions -> id, question_data, user_id users -> id, fname, lname
I have 3 tables with the following columns : * users : user_id *
I have the following tables: users: user_id user_name message: message_id thread_id to_id from_id title
I have following tables: users(id, name) posts (id, text, userId) comments (id, text, userId,
I have the following tables: users id | name info id | info |
I have 2 following tables: Users (user_id, user_name, ... ) Photo (photo_id, user_id, ...)
I have the following tables: team_members userid teamid users uid name_f name_l friends friend_id
I have the following 3 tables: team_data id team_id team_name team_members userid teamid users
I have the following tables: Users: userId , userFirstName , userLastName . holdBilling: bEntityID
In my application I have the following tables: Posts id title content Users id

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.