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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:08:42+00:00 2026-06-18T11:08:42+00:00

table1(users) |ID|name |type | |1 |demo |admin | |2 |demoX |client| table2(visits) |ID|admin_id|visitor_id|visit_date|… |1

  • 0
table1(users)
|ID|name  |type  |
|1 |demo  |admin |
|2 |demoX |client|

table2(visits)
|ID|admin_id|visitor_id|visit_date|...
|1 |1       |2         |2013-01-01|...
admin(fk)->users(id)
user(fk)->users(id)

simple scheduler project, it contain 2 tables.

1st (users) contain all users, 2nd table contain all bookings(visits).

to get all bookings of an admin i run Select * from visits where admin_id=$id;, and join
visitor info from users table.

……..
so basically,

every admin can have many visit

visit must contain (ONE)admin and (ONE)visitor.

how can i setup this kind of relation in datamapper 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-18T11:08:43+00:00Added an answer on June 18, 2026 at 11:08 am

    This should do it:

    class Users extends Datamapper
    {
        public $has_many = array(
            'admin' => array(
                'class' => 'users',
                'other_field' => 'admin', // FK = admin_id
            ),
            'visitor' => array(
                'class' => 'users',
                'other_field' => 'visitor', // FK = visitor_id
            ),
        );
    }
    
    class Visits extends Datamapper
    {
        public $has_one = array(
            'admin' => array(
                'class' => 'users',
                'join_self_as' => 'admin', // FK = admin_id
            ),
            'visitor' => array(
                'class' => 'users',
                'join_self_as' => 'visitor', // FK = visitor_id
            ),
        );
    }
    
    // then in your controller you can do:
    
    $visit = new Visitor(1);
    echo $visit->admin->name; // echo's 'demo';
    echo $visit->visitor->name; // echo's 'demoX';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables Table: Users userid (int, PK) name (varchar) type (enum) Table:
I have a table of Users: id, type, name and a table of Articles:
I have a table with users: name | country | .. | UK |
I have 3 tables users(id,name),groups(id,name) and users_groups(user_id,group_id). users and groups have many to many
these are my tables: TABLE 'USERS' ID NAME AGE 01 John 22 02 Gloria
Consider the following tables: users and tweets user_id name tweet_id user_id tweet spam -----------------
I have the following tables: users +----------+----------+----------+ | id | name | dob |
I have 3 tables: users (id, name) currency (id, name) accounts (id, user_id, currency_id,
Design of SQL Table Users: Columns: ID(Primary Key), Name, Age, Zip. I am displaying
Table join : |ID|admin|user |data| |1 |00001|00002|XXXX| admin (fk) = users.id , user (fk)

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.