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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:16:38+00:00 2026-05-22T16:16:38+00:00

Let’s say I have three tables: users , books , and users_books . In

  • 0

Let’s say I have three tables: users, books, and users_books.

In one of my views, I want to display a list of all the books the current user has access to. A user has access to a book if a row matching a user and a book exists in users_books.

There are (at least) two ways I can accomplish this:

  • In my fetchAll() method in the books model, execute a join of some sort on the users_books table.
  • In an Acl plugin, first create a resource out of every book. Then, create a role out of every user. Next, allow or deny users access to each resource based on the users_books table. Finally, in the fetchAll() method of the books model, call isAllowed() on each book we find, using the current user as the role.

I see the last option as the best, because then I could use the Acl in other places in my application. That would remove the need to perform duplicate access checks.

What would you suggest?

  • 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-22T16:16:39+00:00Added an answer on May 22, 2026 at 4:16 pm

    I’d push it all down into the database:

    1. Doing it in the database through JOINs will be a lot faster than filtering things in your PHP.
    2. Doing it in the database will let you paginate things properly without having to jump through hoops like fetching more data than you need (and then fetching even more if you end up throwing too much out).

    I can think of two broad strategies you could employ for managing the ACLs.

    You could set up explicit ACLs in the database with a single table sort of like this:

    • id: The id of the thing (book, picture, …) in question.
    • id_type: The type or table that id comes from.
    • user: The user that can look at the thing.

    The (id, id_type) pair give you a pseudo-FK that you can use for sanity checking your database and the id_type can be used to select a class to provide the necessary glue to interact the the type-specific parts of the ACLs and add SQL snippets to queries to properly join the ACL table.

    Alternatively, you could use a naming convention to attach an ACL sidecar table to each table than needs an ACL. For table t, you could have a table t_acl with columns like:

    • id: The id of the thing in t (with a real foreign key for integrity).
    • user: The user the can look at the thing.

    Then, you could have a single ACL class that could adjust your SQL given the base table name.

    The main advantage of the first approach is that you have a single ACL store for everything so it is easy to answer questions like “what can user X look at?”. The main advantage of the second approach is that you can have real referential integrity and less code (through naming conventions) for gluing it all together.

    Hopefully the above will help your thinking.

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

Sidebar

Related Questions

Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
Let's say I have a drive such as C:\ , and I want to
Let's say I have two tables orgs and states orgs is (o_ID, state_abbr) and
Let's say I have a C++ Visual Studio 2010 solution with 2 projects: one
Let's say I have one class User, and it has a property of type
Let's say you create a wizard in an HTML form. One button goes back,
Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>

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.