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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:54:50+00:00 2026-05-19T16:54:50+00:00

I’m not sure how to ask this question, so I’ll be as clear as

  • 0

I’m not sure how to ask this question, so I’ll be as clear as I can with an example.

In an app like facebook, a Profile can have multiple ProfilePictures. At any given time, one of these is the “selected” ProfilePicture (assuming a ProfilePicture has been uploaded).

Instinctively, I would model this like:

Table: Profile
--------------
ProfileID
SelectedProfilePictureId //fk to ProfilePicture
Name, Age, Etc

Table: ProfilePicture
---------------------
ProfilePictureId
ProfileId //fk to Profile, indicating which Profile this picture belongs to
Url, DateTaken, Etc

At this point, these tables point to each other and it just seems “wrong” to me. It makes it easy to query for Profiles without SelectedProfilePictures or to get a Profile’s SelectedPicture, but inserts and updates are a little wonky.

Is this bad form? Should the Profile table be completely independant of the ProfilePicture table? Is there a “correct” way to model this according to database design theory, or is it up to the descretion of the programmer?

  • 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-19T16:54:51+00:00Added an answer on May 19, 2026 at 4:54 pm

    You are correct, this is called a circular reference and you actually cannot make the database do it.

    One simple solution is a “preferred” flag on the child table of pictures. But you have a biz logic issue here: only one row for a given person can be preferred. So when anybody marks a new one as preferred, you must clear any others.

    A safer solution is to add a third table “preferredPictures” with foreign keys to Profiles and ProfilePictures. Make it unique on profileId, so it can never have more than one entry. This forces a deletion of a prior entry before insertion of a new one. Or of course you can just do an update of an existing.

    EDIT: in response to comment.

    1) No circular reference because Profiles is parent of both child tables, it does not loop around to Profiles

    Profiles
       |  |
       |  +-----> PreferredPicture
       |  +----->
       |  |
      \|/ |
    ProfilePictures
    

    2) Primary key of Preferred Picture is ProfileId, it is technically a 1:1 child table of Profiles.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I am using Paperclip to handle profile photo uploads in my app. They upload

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.