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

  • Home
  • SEARCH
  • 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 1003461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:59:02+00:00 2026-05-16T07:59:02+00:00

I am confused about how to set this up using Cake’s conventions. I have

  • 0

I am confused about how to set this up using Cake’s conventions. I have a table of users (pretty standard: id (pk, auto-increment), username, password), a table of groups (also pretty standard: id, name, user_id) and a practice table (like a doctor’s practice, not like “practice makes perfect”). The practice table will be owned by one user (that belongs to a dr group) and will zero or more other users that belong to the practice (and are standard members).

here’s a very rough drawing of what I am thinking:

user ---(belongs to)---> group
  |
  |
  +<----(belongs to)---- practice
  |                        ^
  |                        |
  +-------------------(belongs to)

I understand how to make sure that only members of group “caretaker” can own a practice and I know how to make sure that each user has one group and all of that.

Normally I would understand how to make “practice has many user” and “practice belongs to user”. Where I’m getting stumped, though, is how do I specify that a practice “has one” user but also “has many” users. This is because the practice doesn’t know the groups that a user belongs to in Cake. And (to my knowledge), I can’t just say “practice.owner_id is a foreign key that matches user.id” because Cake won’t understand this.

If I am mistaken, can you please provide an explanation/link to a doc to help me on my way? Thanks SO.

  • 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-16T07:59:03+00:00Added an answer on May 16, 2026 at 7:59 am

    I can’t just say “practice.owner_id is a foreign key that matches user.id” because Cake won’t understand this.

    Well, you can… just not the way you are thinking.

    You set up a belongsTo on your Practice model… your user_id field in the Practice will be the owner. Then, set up another belongsTo on your User model with a practice_id field. If you want, you can even set up a hasMany on the practice to tie it to the user. Just name the belongsTo and hasMany associations differently. Call the Practice belongsTo User relationship Owner in your model. Then, when you actually pull records out of the database, you’ll get an Owner array and a User array on you Practice (assuming appropriate $recursive levels.)

    Reading over that, that might be confusing… to sum up:

    Associations in User:

    • belongsTo Practice

    Associations in Practice:

    • hasMany User
    • belongsTo Owner (alias
      for User)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am really confused about this.I have set the background color of the whole
I'm confused about this one. I'm using razor with MVC 3 and I have
I'm a bit confused about using STL set::find() for a set of my own
I’m confused about this; instead of writing tweepy codes like- auth=tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret)
I am a little confused about how I set and get the instance variables
I'm super confused about field access JPA-annotated POJOs. How are you supposed to set
I am confused about cron jobs. How do I set Cron in 18 hours
I am a little confused about Accept-Encoding . I have Web Service which would
I'm using SQLite as my database, and I'm a little bit confused about how
I'm a little bit confused about how to approach this. I had never used

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.