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

  • Home
  • SEARCH
  • 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 6858397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:09:13+00:00 2026-05-27T02:09:13+00:00

I need help constructing a CodeIgniter Datamapper ORM query that includes join fields. I

  • 0

I need help constructing a CodeIgniter Datamapper ORM query that includes join fields.
I have a table of Merchants and a table of Vendors.
They have a many-to-one relationship, that is, many Merchants are part of a single Vendor.

Thus, my datebase tables, following the Datamapper ORM convention are:

merchants

vendors

merchants_vendors

Furthermore, in the merchants_vendors table, I have join fields ‘role’ and ‘admin’.
Obviously, this data must be placed in the join table, if it were placed in the Merchants table, I wouldn’t be able to define roles and administrators per Vendor.

Lastly, Merchants are related to Users by a one-to-one relationship.
Think of Merchants as just an extension of Users.

I’m attempting to create a PHP array from the data that follows this data structure, but I can’t seem to get the role and admin fields populating properly. I removed redundant columns for your simplicity:

[vendor] => Array
        (
            [id] => 1
            [name] => Vendor1
            [users] => Array
                (
                    [0] => Array
                        (
                            [id] => 277
                            [username] => merchant1
                            [firstname] => Merchant1
                            [merchant] => Array
                                (
                                    [id] => 1
                                    [user_id] => 277
                                    [role] => Sales
                                    [admin] => 0
                                )

                        )

                    [1] => Array
                        (
                            [id] => 282
                            [username] => merchant2
                            [firstname] => Merchant2
                            [merchant] => Array
                                (
                                    [id] => 2
                                    [user_id] => 282
                                    [role] => Software
                                    [admin] => 1
                                )

                        )

                )

        )

Here’s the code I’m using – Assuming we know the Vendor ID:

$v = new Vendor($id);
if($v->exists())
{
    $d['vendor'] = $v->to_array();
    $m = new Merchant();
    $m->where_related_vendor('id', $v->id)->get();
    if($m->exists())
    {
        foreach($m as $mK => $mV)
        {  
            $u = new User();
            $u->where_related_merchant('id', $mV->id)->get();
            $d['vendor']['users'][$mK] = $u->to_array();
            $d['vendor']['users'][$mK]['merchant'] = $mV->to_array();
        }
    }
}
$this->load->view('myview', $d);

This gets me as far as the above PHP data structure without the role and admin.
I am well aware of the include_join_fields() function – but I cannot seem to get it working. Specifically, I tried $m->vendor->include_join_fields(); Then tried to access the role/admin fields by $mV->vendor->join_role and $mV->vendor->join_admin – but that doesn’t work.

Your help is much appreciated!

  • 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-05-27T02:09:13+00:00Added an answer on May 27, 2026 at 2:09 am

    The solution was to use include_join_fields() on the $mV object inside the forloop:

    $v = new Vendor($id);
    if($v->exists())
    {
        $d['vendor'] = $v->to_array();
        $m = new Merchant();
        $m->where_related_vendor('id', $v->id)->get();
        if($m->exists())
        {
            foreach($m as $mK => $mV)
            {  
                $u = new User();
                $u->where_related_merchant('id', $mV->id)->get();
    
                $mV->vendor->where('id', $v->id)->include_join_fields();
    
                $d['vendor']['users'][$mK] = $u->to_array();
                $d['vendor']['users'][$mK]['merchant'] = $mV->to_array();
                $d['vendor']['users'][$mK]['merchant']['role'] = $mV->vendor->join_role;
                $d['vendor']['users'][$mK]['merchant']['admin'] = $mV->vendor->join_admin;
            }
        }
    }
    $this->load->view('myview', $d);
    

    Ongoing discussion in the CodeIgniter forums.

    I will post more information as it arrives.

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

Sidebar

Related Questions

I need help constructing a linq query that will return a list of usernames
I need help constructing a monitor that implements a semaphore, and simple C example
I need a help constructung an sql query for mysql database. 2 Table as
i need help with disk_total_space function.. i have this on my code <?php $sql=select
I need help on regex or preg_match because I am not that experienced yet
I'm having a hard time constructing the URL for a query that has more
I need the fields in 1 table contingent on 1 property matching rows in
Right now, I have a query that gets me 3 columns. SELECT a.studentID, a.classdetailID,
I need help in constructing RegEx for the search function on my website. I
i need help creating a count down timer in php. the problem is that

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.