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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:38:42+00:00 2026-05-26T02:38:42+00:00

A user can be in groups. And an item/product is assigned groups that can

  • 0

A user can be in groups. And an item/product is assigned groups that can see the item. Users can see that item if they are in one of the assigned groups.

I want neither public (anonymous users in no groups) nor groupless users (logged in users not in any groups) to see the item. But I want the interface to allow assigning the item an ‘all/any groups’ attribute so that users that are in any group at all can see the item.

Where/How should I store this assignment?

p.s. I expect the technique to also be extended to other entities, for example I’d assign a file to a category, and groups are linked to categories. so when a file is marked as visible by the ‘all/any category’ then if the user (thru groups and group-categories) is linked to at least one category then the file is visible to them.

Decision:

It seemed the choice was whether to implement as a row in a entity-groups table or as fields in the entity table. The chosen answer used the former.

And either managing the group membership in a table or adding JOIN conditions. The chosen answer used the former, but I’m going to use the latter. I’m putting an indirection between the query and usage so if (when) performance is a problem I should be able to change to a managed table underneath (as suggested) without changing usage.

I’ve other special groups like ‘admin’, ‘users’, etc. which can also fit into the same concept (the basis simply being a list of groups) more easily than special and variable field handling for each entity.

thanks all.

  • 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-26T02:38:42+00:00Added an answer on May 26, 2026 at 2:38 am

    As mentioned by both Martin Smith and Mikael Eriksson, making this a property of the entity is a very tidy and straight forward approach. Purely in terms of data representation, this has a very nice feel to it.

    I would, however, also consider the queries that you are likely to make against the data. For example, based on your description, you seem most likely to have queries that start with a single user, find the groups they are a member of, and then find the entities they are associated to. Possibly something lke this…

    SELECT DISTINCT -- If both user and entity relate to multiple groups, de-dupe them
      entity.*
    FROM
      user
    INNER JOIN
      user_link_group
        ON user.id = user_link_group.user_id
    INNER JOIN
      group_link_entity
        ON group_link_entity.group_id = user_link_group.group_id
    INNER JOIN
      entity
        ON entity.id = group_link_entity.entity_id
    WHERE
      user.id = @user_id
    

    If you were to use this format, and the idea of a property in the entity table, you would need something much less elegant, and I think the following UNION approach is possibly the most efficient…

    <ORIGINAL QUERY>
    
    UNION       -- Not UNION ALL, as the next query may duplicate results from above
    
    SELECT
      entity.*
    FROM
      entity
    WHERE
      EXISTS (SELECT * FROM user_link_group WHERE user_id = @user_id)
      AND isVisibleToAllGroups != 0
    
    -- NOTE: This also implies the need for an additional index on [isVisibleToAllGroups]
    

    Rather than create the corner case in the “what entity can I see” query, it is instead an option to create the corner case in the maintenance of the link tables…

    1. Create a GLOBAL group
    2. If an enitity is visible to all groups, map them to the GLOBAL group
    3. If a user is added to a group, ensure they are also linked to the GLOBAL group
    4. If a user is removed from all groups, ensure they are also removed from the GLOBAL group

    In this way, the original simple query works without modification. This means that no UNION is needed, with it’s overhead of sorting and de-duplication, and neither is the INDEX on isVisibleToAllGroups needed. Instead, the overhead is moved to maintaining which groups a user is linked to; a one time overhead instead.

    This assumes that the question “what entities can I see” is more common than changing groups. It also adds a behaviour that is defined by the DATA and not by the SCHEMA, which necessitates good documentation and understanding. As such, I do see this as a powerful type of optimisation, but I also see it as a trades-and-balances type of compromise that needs accounting for in the database design.

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

Sidebar

Related Questions

I want to programmatically make it so that users can see only particuar items
Using dojo.dnd, I want to allow a user to drag only one item at
I'm trying to build a simple User Template system so that my users can
How can you check to see if a user can execute a stored procedure
Can a JApplet use a JFileChooser so that the user can select a file
I've got a simple temporal table that looks like this: Table: item_approval item user
I have a number of objects. They can be sorted into groups. When a
I have a webpage that dynamically loads a user control. Each user control can
Let's say I have two entities: Group and User. Every user can be member
Using my c++ program how can I find out what group the current user

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.