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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:47:21+00:00 2026-05-23T16:47:21+00:00

Let’s say that I’m building an engine that has many blogs and many users.

  • 0

Let’s say that I’m building an engine that has many blogs and many users. Users can have many blogs and blogs can have many users (users hasAndBelongsToMany blogs). I would create a pivot table called users_blogs which would look like this:

id user_id blog_id role

1  1       1       admin
2  1       2       poster
3  2       2       admin

So, user 1 belongs to blogs 1 and 2, and user 2 belongs to blog 2. User 1 is an admin in blog 1, and a poster in blog 2, and user 2 is an admin in blog 2.

There will also be posts. users_blogs will have many posts, and posts can have many users_blogs. They would be joined with a pivot table that would look like this:

id users_blog_id post_id
1  2             1
2  3             1

So, referring to users_blogs, user 1 on blog 2 collaborated with user 2 on blog 2 to create post 1.

I’m relatively new to MVC, so I’m wondering if A) the “role” data in the first table is where it’s supposed to be?, and B) Is there a more correct way to do this structure? Frameworks will do the magic for me, I just want to make sure that this makes sense, and I’ve got the correct naming conventions. I’m using Cakephp, but I also think that this question could be answered by a Rails programmer.

Thank you!

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

    It looks like you’re on the right track. If I understand you, this is how it should be:

    I didn’t completely understand one of your statements, so I’m going on the assumption that a post belongsTo a single blog like most.

    First issue is, your “pivot table” naming convention must be in alphabetical order – so it should be blogs_users, not users_blogs. Seems minor, but won’t work otherwise.

    Associations:

    blog hasMany post
    post belongsTo blog
    
    user hasAndBelongsToMany blog //allowing more than one user to be associated to a blog
    blog hasAndBelongsToMany user
    
    user hasAndBelongsToMany post //allowing more than one user to be associated to a post
    post hasAndBelongsToMany user
    
    role hasAndBelongsToMany user //better to keep roles in a table that just a string
    user hasAndBelongsToMany role //use 'with'=>'blogs_users' in your association
                                  between user/roll
    

    Tables:

    users            (id, name, ...etc)
    blogs            (id, title, ...etc)
    roles            (id, role)
    blogs_users      (id, user_id, role_id, blog_id)
    posts            (id, title, blog_id)
    posts_users      (id, post_id, user_id)
    

    Update:

    I’m not the best at this – still somewhat learning myself, but – off the top of my head, you could get the posts from blog 1 created by user 1 via something like this:

    $blogId = '1';
    $userId = '1';
    $posts = $this->Post->find('all', array(
        'conditions' => array(
            'User.id' => $userId,
            'Blog.id' => $blogId
        )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I have a binary that I am building, and I include
Let's say I'm creating an OpenGL game in C++ that will have many objects
Let's say I'm building a data access layer for an application. Typically I have
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.
Let's suppose I have a Discussion model, and that a discussion can be tagged.
Let's say that I have a set of relations that looks like this: relations
Let's say I have a dataset, which can be neatly classified using weka's J48
Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting

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.