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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:28:52+00:00 2026-05-31T09:28:52+00:00

So, In my project there are groups and users. Each users belongs to a

  • 0

So, In my project there are groups and users. Each users belongs to a group, and one of those users is also an Admin of the group. I have been struggling to figure out how to map those relationships.

Currently with the set up I am creating a form that will create a new group, and its admin at the same time (so also a new user).

I want to know how to set this up so A- I can save the user and group correctly and B- So in the form both the user and the group information can be validated and show the errors.

This is the current layout of my DB tables

Groups Table:

`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(10) unsigned DEFAULT NULL,
`name` varchar(60) NOT NULL,
`account_active` tinyint(1) DEFAULT NULL,
`create_date` date NOT NULL,
`last_modified` date NOT NULL,
`delete_date` date DEFAULT NULL,
 PRIMARY KEY (`id`),
 KEY `groups_fk_admin` (`administrator`),
 CONSTRAINT `groups_fk_admin` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)

And the Users Table:

`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`group_id` int(10) unsigned DEFAULT NULL,
`email` varchar(200) NOT NULL,
`password` varchar(40) NOT NULL,
`first_name` varchar(45) NOT NULL,
`last_name` varchar(45) NOT NULL,
`create_date` date NOT NULL,
`last_modified` date NOT NULL,
`delete_date` date DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`),
KEY `users_group_id_fk` (`group_id`),
CONSTRAINT `users_group_id_fk` FOREIGN KEY (`group_id`) REFERENCES `groups` (`id`)

Then my models are currently setup like….

Group Model:

 public $hasMany = array(
    'User' => array(
        'className' => 'User',
        'foreignKey' => 'group_id',
        'dependent' => false,
    )
);

public $belongsTo = array(

    'Administrator' => array(
        'className' => 'User',
        'foreignKey' => 'user_id',

    )
);

Users Model:

 public $hasMany = array(
    'Admin' => array(
        'className' => 'Group',
        'foreignKey' => 'user_id',
        'dependent' => false,

    ),

);

public $belongsTo = array(
    'Group' => array(
        'className' => 'Group',
        'foreignKey' => 'group_id',
  )
);

Thank you for your help! And let me know if I can provide any more information.

  • 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-31T09:28:53+00:00Added an answer on May 31, 2026 at 9:28 am

    Group hasMany User

    User belongsTo Group

    And just add another column to the Users table called is_admin or whatever, with the value of the ID of the group it is admin of.

    For certain actions you should simply check if it passes a certain condition. So if you want to check if a user is an administrator of group 4, it has to check if it’s is_admin id is equal to 4. You could set to 0 for ‘normal’ users.

    Being a property of a user, administrator shouldn’t be declared in your DB relation with a User hasMany admin and a group belongsTo admin, admin isn’t a model on its own. It is a property of User, a role.

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

Sidebar

Related Questions

I have a model class Project and for each model instance, there should be
Is there a way to list which users and AD groups have permissions to
I find useful groups.google.com/group/comp.lang.prolog/topics cs.cmu.edu/afs/cs/project/ai-repository/ai/areas/ google.com/Top/Computers/Programming/Languages/Prolog/Implementations/ allisons.org/ll/Logic/Prolog/Examples/ prolog.info/ Maybe there are else useful links?
I have a project where there are Windows, FreeBSD and Linux servers. I have
So I have a project where there is some automatic initialization going on through
I am working on one project where there is a functionality need to implement
I have Groups that has_many projects. I also created an order view that is
The project I have been managing has ran into an issue of updating contents
I'm working on a web-based project that users will access after having been authenticated
In my project there are large no. of FIXME / TODO which are 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.