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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:07:00+00:00 2026-05-29T08:07:00+00:00

User Groups Link User1 User2 Time (or some other relevant link data) Posts A

  • 0

User

  • Groups
    • Link
      • User1
      • User2
      • Time (or some other relevant link data)
    • Posts

A user can only see a post if the user belongs to a link that belongs to the same group to which the post belongs.

I would like to optimize the database for querying all posts that a given user is allowed to see. What is the best way to structure the database to do this?

Thanks for the help!

EDIT: The above schema is a basic idea to get you started. Thanks again!

  • 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-29T08:07:02+00:00Added an answer on May 29, 2026 at 8:07 am

    This is how I would model this:

    Users(id, etc)

    This is the user list. It contains only user data. The PK will be the id, so there will be an implicit index there

    Groups(id, etc)

    This is the group list. It contains only group data. The PK will be theid, so there will be an implicit index there

    User_Groups(userId, groupId, etc)

    This is the way to link users to groups. It needs to have the foreing keys to the users and groups and you can add any additional data to it, for instance, date when the user joined the group. The PK here will be a compound key between userId and groupId, so the index will be userId and groupId. You will also want to have an additional index in the groupId, because the “main order” will be given by userId, not by groupId

    Posts(id, createdByUserId, belongsToGroupId, etc)

    This is the lists of posts. Posts are created by only a user and belong to only one group. To display a post you’ll join createdByUserId with Users table (to display the name of the user who created the post). Additionally, you’ll want to check if the user who wants to see the post is actually allowed to see it. So, you’ll go to the User_Groups table and use a WHERE clause similar to $currentUserId = users_groups.userId and $currentPostBelongsToGroupId = users_groups.groupId (OR you can join the table on post.belongsToGroupId = user_groups.groupId).

    This is the general idea. Now, to focus on “optimize the database for querying all posts that a given user is allowed to see” you should basically do what I stated in the Posts entity description. As you’re not looking for a particular post you’ll have to join Posts with User_Groups (this join will use the groupId index created on the User_Groups entity) and then use the WHERE clause stated there too. That clause will use the compound primary key created on that entity. And that’s it. It seems to be a fully indexed path.

    Now, why didn’t I add the link entity you’ve got on your question? Because I’ve not idea what it is and you didn’t answer my comment on top asking what it was. If it was a link between 2 users then it shouldn’t belong to a group because users belong to groups separately, not in pairs. Apart from that, if the link is what I assumed then it wouldn’t affect at all the performance on how a user see his/her own allowed posts. Possibly related question to the link entity

    Hope this helps or guide you to a better solution 🙂

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

Sidebar

Related Questions

Can we control/give our page security depending the user groups in symfony 1.4. How
I have this relationship where User can create a document(trip) and invite other users
I'm gonna add authorization, user and groups management to my application, basically... you will
I often use the net user command to have a look at AD groups
I know certain groups of games (like the ..with friends games), allow a user
I created 3 tables: User User-Group Group Where I can have a many-to-many relationship.
Ok SO, I have a user table and want to define groups of users
I have a User and Group model. User has_many Groups and Group belongs_to User
I have a Users model that can have many Groups through Memberships. If a
I'm trying to build a simple User Template system so that my users can

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.