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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:08:06+00:00 2026-06-12T22:08:06+00:00

I am currently working on an application where we are basically building up a

  • 0

I am currently working on an application where we are basically building up a graph between “items”.
I think there are different kinds of links between those items, but I am struggeling right now to decide how to model those, especially bi-directional links.

1. Example:

ItemB --isChildOf---> ItemA
ItemA --isMasterOf--> ItemB

The same I think could be modelled like this:

Example 2

ItemA <---> ItemB

In my Database model I currently model my links like this:

* sourceID
* targetID
* relationType (e.g. isMasterOf, isChildOf, maybe more...)

Do I also need the direction as a field in my table? So far I don’t have it as a separate field, because IMO the direction is implicitly defined by sourceID and targetID.

I am not sure in which situations I would need Example 1 and in which cases Example 2 is enough. I think Example 1 is like twitter, where UserA can follow userB but maybe not the other way round. Facebook on the other hand is always Example2 in my opinion.

Hope my question makes sense.

  • 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-12T22:08:08+00:00Added an answer on June 12, 2026 at 10:08 pm

    If you want a solution that is as generic as possible and will work in any simple graph modeling case (one-to-many/many-to-one, many-to-many), just model the links as (source_id, target_id) pairs in a separate link table. That way you can both

    • model bidirectional links by having edge pairs (a.id, b.id) and (b.id, a.id) and unidirectional links by having one of those depending on direction
    • differentiate edge direction by looking at which node is the source and which is the target – no need to have a separate direction field.

    If you want to make an elegant solution for a particular case where there are actual constraints on what kind of graph you want to model, you will first need to decide

    1. what kind of links you want to allow between objects: will they always be uni- or bidirectional, or do you need to differentiate both and
    2. whether it will be a tree-like structure where one object can have just one parent but many children, or a more generic graph where one object may have several edges coming and going.

    Regarding the first point, if you KNOW all the links will be of the same kind, you don’t really need to differentiate edge (source_id, target_id) from edge (target_id, source_id) in the code, because both mean just an edge between two objects/nodes.

    As far as the second point goes: if the graph you want to model resembles a tree or a forest (every object has 0 or 1 parents and 0 to n children, all the links are of the same type – uni- or bidirectional), you can just add something like parent_id to the objects themselves instead of modeling the connections on a separate link table.

    Obviously, if you need to have other attributes to the edges (such as weight or some kind of type attribute other than direction), you’ll have to add fields accordingly. In that case it would make most sense to model the edges on a separate table in any case, since the edges will not be just simple links between nodes but objects with actual properties.

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

Sidebar

Related Questions

The web-based application I’m currently working on is growing arms and legs! It’s basically
I am currently working on an application that has different permissions/users for the local
I am currently working on an application which requires different behaviour based on whether
I am currently working on a Windows.Forms application. It's basically a simple motion detection
In the application I am currently working on there is a backend java app
Am currently working on an application that requires users to submit posts and comments
I am currently working on an application in VB.NET im my spare time and
I'm currently working in an application that has to navigate a webpage and recollect
I'm currently working on an application that allows people to schedule Shows for an
I'm currently working on an application written in C#, which I'm embedding IronPython in.

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.