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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:34:41+00:00 2026-05-10T21:34:41+00:00

I have the need to create the functionality to allow my registered users to

  • 0

I have the need to create the functionality to allow my registered users to associate themselves with other uses and create a family. My database tables look something like this:

db.persons – (Bob, Jane, Timmy, etc)

  • id
  • name
  • email

db.persons_persons

  • id
  • person__id_parent
  • person_id_child
  • relationtype_id

db.relationtypes – (spouse, child, nephew, etc)

  • id
  • name

With this structure, I should be able to specify that Bob is a Spouse of Jane in the persons_persons table. The record in db.persons_persons would look something like (psuedo):

ID | person_parent | person_child | relationtype 1  | Bob           | Jane         | Spouse 2  | Bob           | Timmy        | Child 

I realize this could cause some data fragmentation since if Bob and Jane are married, then a child of one would have to be associated with the other. However that is not my question. My question is whether or not this database setup is ‘most-correct’ for use in a cakePHP application.

  • 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. 2026-05-10T21:34:41+00:00Added an answer on May 10, 2026 at 9:34 pm

    Firstly, CakePHP will automatigally inflect a people table into a people controller and a person model, so you don’t need to call it persons. Then I’d call the lookup table relationships rather than persons_persons.

    I’d call the fields in your relationships table person_id, relation_id and relation_type_id, and then add an underscore in your relationtypes table name so it becomes relation_types.

    I think this is more semantic.

    You could still use a hasAndBelongsToMany association, and make use of the automagic ‘with‘ associations offered by CakePHP (1.2 only) to access the additional data in the HABTM table for relation type.

    However, I’d be tempted to use:

    • Person hasMany Relation
    • Relation belongsTo Person, Relation, RelationType

    In your app, is a persons relationship implied by someone else’s relationship to them? I.e. if you find Person.id = 1 you might get all their relations, e.g. Person.id 2, 3 and 4. But if you find Person.id 2, you would not automatically get Person.id = 1, unless there was another record in the relations table that represented that relationship.

    To achieve this, you can set up another assocation:

    • Person hasMany Relation1 with foreignKey person_id
    • Person hasMany Relation2 with foreignKey relation_id
    • Relation belongsTo Person, Relation, RelationType

    Note, you can achieve this dual relationship with HABTM too.

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

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer There is no nice way to do it. You can… May 11, 2026 at 10:47 am
  • added an answer The standard convention in the MSDN library seems to refer… May 11, 2026 at 10:47 am
  • added an answer To Location 1: SELECT DISTINCT organization_id FROM organization_locations ol WHERE… May 11, 2026 at 10:47 am

Related Questions

I have the need to create the functionality to allow my registered users to
I have the need to take a string argument and create an object of
I have the need to read the Thunderbird address book on the fly. It
I have the need to copy the entire contents of a directory on a
I have the need to express simple conditionals as program input. The input must
I've got a VB.NET WinForms app in which I have the need to refer
I have the following code that I need to add an additonal object to
I have the following Query and i need the query to fetch data from
I have the following VB.net interface that I need to port to C#. C#
I have the current basic structure for each domain object that I need to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.