I am building an application that is using JSON / XML files to persist data. This is why I indicated “outside of SQL” in the title.

I understand one benefit of join tables is it makes querying easier with SQL syntax. Since I am using JSON as my storage, I do not have that benefit.

But are there any other benefits when using a separate join table when expressing a many-to-many relationship? The exact expression I want to express is one entity’s dependency on another. I could do this by just having a “dependencies” field, which would be an array of the IDs of the dependencies.

This approach seems simpler to me than a separate table / entity to track the relation. Am I missing something?

Feel free to ask for more context.

  • marcos@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    7 months ago

    Joins and tables are abstract concepts, they don’t dictate how you store data on memory or disk or how you read it.

    If you want a specialized data storage, go with whatever format is easier for you to use. But also, the format that is easier to store is not necessarily the easiest one to work on memory.

    • matcha_addict@lemy.lolOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      7 months ago

      Currently, I am storing entities in a JSON array / list. every element in this list corresponds to one instance of that entity.

      I could express a many-to-many relationship as just another field in that entity that happens to be a list / array, or I can imitate a SQL join table by creating a separate JSON list to log an instance of that relation.

      Are there any benefits to the second approach?

      • SzethFriendOfNimi@lemmy.world
        link
        fedilink
        arrow-up
        1
        arrow-down
        1
        ·
        7 months ago

        Mostly storage space and ease of updating records.

        Let’s say you have records of users who watch a TV show.

        You could keep users as a key and shows as an array. Where each array entry is a record of the TV show title, release date, and other info such as time watched by that user.

        In this case you’re duplicate the strings for shows like “Fallout” and the release date thousands of times. And then if there’s an update such as a title change or the streaming service or channel where it’s found you have to find those thousands of subrecords and update them.

        Keeping a reference to another key/json file by some ID makes it easier to do such updates and reduces storage for that data. Except now you have to correlate that data when doing things like reports of what shows were watched by what users.