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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:19:46+00:00 2026-05-28T06:19:46+00:00

I have an application that requires: user owns many projects. project has one owner.

  • 0

I have an application that requires:

user owns many projects.
project has one owner.

user works on many projects.
projects have many users.

so I have 3 tables, users, projects_users, projects.
The relationships are:

one user (owner) — many projects (created_by)

many users (id) —- via projects_users (user_id, project_id) —- many projects (id).

In Codeigniter I’ve set up the following relationships in the datamapper models:

Class Project extends DataMapper {

var $has_one = array(
    'created_by' => array(
        'class' => 'user',
        'other_field' => 'owns'
    )
);
var $has_many = array('user' => array(
        'class' => 'user',
        'other_field' => 'project',
        'join_table' => 'projects_users'));

and…

    class User extends DataMapper {

var $has_many = array(
    'project' => array(
        'class' => 'project',
        'other_field' => 'user',
        'join_table' => 'projects_users'
    ),
    'owns' => array(
        'class' => 'project',
        'other_field' => 'created_by'
    )
);

This doesn’t seem to work however and I get a recursive error.
What is the correct way to represent this relationship in datamapper?

  • 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-28T06:19:46+00:00Added an answer on May 28, 2026 at 6:19 am

    Take a look at Multiple Relationships to the Same Model on the doc page: http://datamapper.wanwizard.eu/pages/advancedrelations.html

    I’m guessing something like this:

    class Project extends DataMapper {
        $has_one = array(
            'owner' => array(
                'class' => 'user',
                'other_field' => 'owned_project'
            )
        );
        $has_many = array(
            'user' => array(
                'class' => 'user',
                'other_field' => 'user_project'
            )
        );
    }
    
    class User extends DataMapper {
        $has_many = array(
            'owned_project' => array(
                'class' => 'project',
                'other_field' => 'owner'
            ),
            'user_project' => array(
                'class' => 'project',
                'other_field' => 'user'
            )
        );
    }
    

    and you would access like this:

    $project = new Project(1); // where "1" is the ID of the project
    $owner = $project->owner->get();
    $project_users = $project->user->get();
    
    // -------------------------------
    
    $me = new User(1); // where "1" is the ID of the user
    $my_projects = $me->owned_project->get();
    

    UPDATE

    You will need to update your projects_users join table to this:

    projects_users
    --------------
    user_id
    owner_id
    owned_project_id
    user_project_id
    

    Note that these all match the “keys” that you declared in your $has_one and $has_many arrays. You will not need to update the users or projects tables (the only requirement is that each of them have a primary key field named “id”).

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

Sidebar

Related Questions

I have an ASP.NET WebForms application that has a feature that requires the user
We have an internal ASP.NET MVC application that requires a logon. Log on works
I have a silverlight application that requires the user to login. The problem is
I have an ASP.NET application that requires impersonation as an administrator user. In web.config:
I have an ASP.NET web forms application that requires that requires that a user
I have an application that requires authentication. Before the user authenticates only a subset
I have a script that calls an application that requires user input, e.g. run
I have an application that requires synchronization and I wanted to inform the user
I have to install an application server that requires an user to write to
In my current application I have a form that requires the user to enter

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.