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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:42:14+00:00 2026-05-18T09:42:14+00:00

In my Quest to understanding Mnesia, I still struggle with thinking in relational terms.

  • 0

In my Quest to understanding Mnesia, I still struggle with thinking in relational terms. So I will put my struggles up here and ask for the best way to solve them.

one-to-many-relations
Say I have a bunch of people,

-record(contact, {name, phone}). 

Now, I know that I can define phone to always be saved as a list, so people can have multiple phone numbers, and I suppose that’s the way to do it (is it? How would I then look this up the other way around, say, finding a name to a number?).

many-to-many-relations
now let’s suppose I have multiple groups I can put people in. The group names don’t have any significance, they are just names; the concept is “unix system groups” or “labels”. Naively, I would model this membership as a proplist, like

{groups [{friends, bool()}, {family, bool()}, {work, bool()}]} %% and so on...

as a field within the “contact” record from above, for example. What is the best way to model this within mnesia if I want to be able to lookup all members of a group based on group name quickly, and also want to be able to lookup all group an individual is registered in? I also could just model this as a list containing just the group identifiers, of course. For use with mnesia, what is the best way to model this?

I apologize if this question is dumb. There’s plenty of documentation on mnesia, but it’s lacking (IMO) some good examples for the overall use.

  • 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-18T09:42:15+00:00Added an answer on May 18, 2026 at 9:42 am

    For the first example, consider this record:

    -record(contact, {name, [phonenumber, phonenumber, ...]}).
    

    contact is a record with two fields, name and phone where phone is a list of phone numbers. As user425720 said it could make sense to store these as something else than strings, if you have extreme requirements for small storage footprint, for example.

    Now here comes the part that is hard to “get” with key-value stores: you need to also store the inverse relationship. In other words, you need something similar to the following:

    -record(phone, {phonenumber, contactname}).
    

    If you have a layer in your application to abstract away database handling, you could make it always add/change the phone records when adding/changing a contact.

    —

    For the second example, consider these two records:

    -record(contact, {uuid, name, [group_id, group_id]}).
    -record(group, {uuid, name, [contact_id, contact_id]}).
    

    The easiest way is to just store ids pointing to the related records. As Mnesia has no concept of referential integrity, this can become out of sync if you for example delete a group without removing that group from all users.

    If you need to store the type of group on the contact record, you could use the following:

    -record(contact, {name, [{family, [group_id, group_id]}, {work, [..]}]}).
    

    —

    Your second problem could also be solved by using a intermediate record, which you can think of as “membership”.

    -record(contact, {uuid, name, ...}).
    -record(group, {uuid, name, ...}).
    -record(membership, {contact_uuid, group_uuid}). # must use 'bag' table type
    

    There can be any number of “membership” records. There will be one record for every users group.

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

Sidebar

Related Questions

I'm using Quest's TOAD for SQL Server on a SQL Server 2000 Server. Here
In my quest to correctly grasp Interface best practices, I have noticed declarations such
I'm still on my quest for a really simple language and I know now
I am on a quest to find the best method to implement this data
I'm hitting another wall in my quest to get better understanding of Git and
In my quest to develop some coding best practices for myself I would like
Going on with my quest to bend protobuf-net to my own will.. I've seen
My last quest was too vague, so I will revise it. I know the
Minor quest - looking for a clean way to dynamically set the size of
In my self-imposed quest to learn Netbeans, I decided to try out an already

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.