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 7715637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:26:11+00:00 2026-06-01T02:26:11+00:00

First up, sorry for the mega-posting of code but… I have the following DB

  • 0

First up, sorry for the mega-posting of code but…

I have the following DB structure (not my choice):

+---------+    +--------------+    +--------+
|  users  |    | users_groups |    | groups |
+---------+    +--------------+    +--------+
|   id    |    |   user_id    |    |   id   |
|  name   |    |   group_id   |    |  name  |
+---------+    +--------------+    +--------+

I’ve created a relationship with FuelPHP’s ORM:

class Model_User extends Orm\Model
{
    protected static $_properties = array(
        'id',
        'name',
    );

    protected static $_has_many = array('usergroup');
}

class Model_Usergroup extends Orm\Model
{
    protected static $_table_name = 'users_groups';

    protected static $_properties = array(
        'user_id',
        'group_id',
    );

    protected static $_belongs_to = array('user', 'group');
}

class Model_Group extends Orm\Model
{
    protected static $_properties = array(
        'id',
        'name',
    );

    protected static $_has_many = array('usergroup');
}

And I’m now trying to get a query to display all the data from the 3 tables using the following:

$data['users'] = Model_User::find()
    ->related('usergroup')
    ->related('usergroup.group')
    ->get();

It’s returning this:

Array
(
    [1] => Model_User Object
        (
            [_is_new:Orm\Model:private] => 
            [_frozen:Orm\Model:private] => 
            [_data:Orm\Model:private] => Array
                (
                    [id] => 1
                    [name] => somename
                )

            [_original:Orm\Model:private] => Array
                (
                    [id] => 1
                    [name] => somename
                )

            [_data_relations:Orm\Model:private] => Array
                (
                    [usergroup] => Array
                        (
                        )

                )

            [_original_relations:Orm\Model:private] => Array
                (
                )

            [_view:Orm\Model:private] => 
            [_iterable:protected] => Array
                (
                )
        )
)

So it’s starting to find the users_groups but stops? Am I even getting at this in the right way? Of course I could get this with a regular query with joins, but it would be ace to actually know how to do this with the ORM.

  • 1 1 Answer
  • 0 Views
  • 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-06-01T02:26:12+00:00Added an answer on June 1, 2026 at 2:26 am

    Gaaaak! It was just missing a PK on the users_groups table…

    class Model_Usergroup extends Orm\Model
    {
        protected static $_table_name = 'users_groups';
        protected static $_primary_key = array('pk_id');
    
        protected static $_properties = array(
            'pk_id',
            'user_id',
            'group_id',
        );
    
        protected static $_belongs_to = array('user', 'group');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off - sorry for the wall of code but it's not too horrendous,
First of all Sorry if my question title sounds stupid.... I have the following
First of I'm very sorry but this questions is not so so specific. All
At first sorry for bad english, Im deafinitely not specialized into math-english. I have
First I am sorry for posting code as ugly style, I didn't know the
First let me say sorry for the amount of code I'm posting below I'm
First the code (sorry if its not 100%) I am no expert and then
First sorry for my English I have a problem with JSON. Assume the following
the first sorry for my english I understand well but not write ok? I
First I am sorry about the length of this post, but I wanted to

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.