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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:26:18+00:00 2026-06-13T02:26:18+00:00

Looking at the tables (aros, acos) generated by the ACL component and for example

  • 0

Looking at the tables (aros, acos) generated by the ACL component and for example the Favorites plugin by CakeDC I see the favorites table with the fields Favorite.user_id, Favorite.model and Favorite.foreign_key.
The last two combined are replacing the good old Favorite.post_id (presuming model has the value 'Post'). It is in a way a HABTM pivot table with a dynamic modelname on one side.
I can see the general and useful idea here but would like to know more about the application of it.

My question(s):

  • Does this pattern have a name?
  • How does this work code-wise? I can see the abstract principle, but what kind of model-code is needed to make this work? Does it involve a patchwork of queries, or does this allow for a smooth one-query implementention? E.g.: I’d like to fetch all marked-as-favorite Posts in the system and their related Users in one go.
  • And does this work both ways? (querying from both the Post model as well as the User model)

I’d like to work towards an abstraction where I put a behavior in place to take care of this pattern.
I did look into the CakeDC code but could not figure out the principle. It’s a little too cryptic for my current knowledge. Hence my question here.

kind regards,
Bart

  • 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-13T02:26:19+00:00Added an answer on June 13, 2026 at 2:26 am

    Does this pattern have a name?

    http://en.wikipedia.org/wiki/Junction_table aka Join Table.

    How does this work code-wise? I can see the abstract principle, but
    what kind of model-code is needed to make this work? Does it involve a
    patchwork of queries, or does this allow for a smooth one-query
    implementention? E.g.: I’d like to fetch all marked-as-favorite Posts
    in the system and their related Users in one go.

    It is just a regular join table, that’s all. You can simply rely on what CakePHP is building up when using the HABTM assocs or refine your query by using joins. See http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#joining-tables.

    The model field is not needed in that “pattern” but allows you to have just one join table that can be used for many different tables/models. For example instead of having tags and users and posts associated by tags_posts and tags_users we simply use the same table and filter by the model field.

    And does this work both ways? (querying from both the Post model as
    well as the User model)

    Yes if you set the HABTM association up in both models.

    Thanks for using our plugins. 😉

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

Sidebar

Related Questions

I'm looking for guidance on encrypting fields (and/or tables if possible) for MySQL. I
I am looking to insert records from xml into two different tables. For example
I have this table, I bet that looking at the tables, you will know
I have MySQL tables looking like that regions table id | region ------------------- 1
I have MySQL tables looking like this: regions table id | region ------------------- 1
I have two tables and I'm looking for the rows in one table where
We are possibly looking at switching our tables, for views in EF 4.3.1. We
We're looking to implement load balancing by horizontally sharding our tables across a cluster
I am looking for a way to display 5 HTML tables in the below
I am looking to make a Master Detail View. I have two tables tbFamily

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.