The AppGini Blog
A few tips and tricks to make your coding life a tiny bit better.

How to handle many-to-many relations in AppGini

Last updated: August 27, 2025: Added parent/children section

Many-to-many relations (also known as N:M relations) describe the relationship between two entities/tables where each can relate to many items of the other. For example, an author can write one or more books, and a book can be written by one author or a team of authors.

Now, if we had a 1:N relation instead, for example, if and author can write many books, but a book can be written only by a single author rather than a team of authors, we’d have a simple relationship between books and authors tables. In AppGini , we’d simply create a lookup field in books table to link it to authors as shown below.

The lookup field ‘author’ field inside ‘books’ table tells who is the
author of a book. However, this has a limitation where a book can have
one and only one
author.

A naive approach to many-to-many relations: author1, author2, …

In the AppGini screenshot above, we created a lookup field in the books table to link it to an author. But that’s a single author. What if the book was authored by 2 or 3 authors? A first thought that might jump to our minds in this case is to add 2 more lookups in the books table for author2 and author 3:

Trying to handle the case where a book has more than one author by
adding more lookup fields to the ‘books’
table.

But the above approach has several limitations…

First, it’s not scalable . What if we got a new book that has 5, or 10 authors? Yes, that can happen ! We’d then have to go back to the project file, add a few more lookup fields, regenerate the app and re-upload it to our web server. Although AppGini makes this process smooth, it’s still a lot of work to add a new book entry. We’d better get our database structure correct at the beginning and keep schema changes to a minimum when users are actually using our app in production environments.

In addition, this makes it harder to perform searches . What is we want to find books wrote by a specific author? We’d then have to look for books whose author1 is x, or author2 is x, or author3 is x … Have 10 author lookup fields in your books table? Good luck with searching through that!

A smarter approach: intermediate (or junction) tables

To avoid the above issues, a much better approach is to create an intermediate table that has a lookup field to books, and another one to authors. This way, if a book has 5 authors, it would have 5 records in the intermediate table, where the book lookup field points to the same book, while the author lookup field points to a different author in each of the 5 records.

An author can write one or more books, and a book can be written by
one author or a team of authors. To describe this relationship
correctly, we need to have an intermediate (or junction) table that
links books to authors. Diagram source:
Wikipedia
.

Here is how this would look like in AppGini:

‘books_authors’ is an intermediate table to represent the
many-to-many relationship between ‘books’ and ‘authors’ by having 2
lookup fields, one to ‘authors’ and another to
‘books’.

Is this a scalable approach? Certainly. Although it’s unlikely to have a book written by 1000 authors, there are other examples where this might be true. Consider a college course taken by thousands of students. A ‘courses_students’ intermediate table can very easily handle this by adding a record for each student enrolled in the course.

Does this make it easier to search? Yep. If you go to the books_authors table and search for a specific author, you are searching only one field, the ‘author’ field. And you’d get all books written by that author, whether she wrote it alone, or with other authors.

Parent/Children Features for Many-to-Many (N:M) Relationships

AppGini has recently added significant enhancements to how parent/children relations are managed and displayed, making many-to-many setups even more intuitive.

Visualizing Junction Tables Under the Main Record

When you set up an intermediate (junction) table (like books_authors), AppGini now lets you easily display all related records directly under the detail view of either parent table (e.g., under a specific book or author).

  • Parent/Children Settings:
    Parent/Children Settings button In the AppGini desktop app, when you select a parent table (such as books or authors), you’ll notice a Parent/Children settings button. Clicking it opens a window where you can configure how child (junction) records are displayed.

    Parent/Children Settings dialog

  • Show tab below detail view:
    You can enable a tab to appear below the detail view for each parent record, listing all linked child (junction) records. For example, when viewing a book, you’ll see a list of all its authors (as rows from the books_authors table) at the bottom of the detail page, and vice versa for authors.

  • Show icon:
    Optionally, you can display an icon next to each tab to help users quickly identify the child table, especially helpful if there are several related tables.

  • Auto close modal after saving changes:
    When editing child records, you can set AppGini to automatically close the edit window when changes are saved, speeding up workflows when adding or editing many records.

  • Copy child records when copying parent:
    If you duplicate a parent record (like a book), AppGini can automatically copy all related child records (e.g., all the books_authors entries for that book) and re-link them to the new parent. This saves time and maintains relational integrity.

Child Info and Quick Add in Table View

  • Display child info in table view:
    You can now display a count of child records (like number of authors for each book) directly in the main table view. This allows you to quickly see, for example, how many authors are linked to each book without drilling into the details.

  • Add new children from table view:
    AppGini allows adding new linked records right from the table view, making it much faster to manage many-to-many relationships.

Example showing list of child records under main record in an AppGini app Example showing list of child records under main record in an AppGini app

Summary of Many-to-Many in AppGini with New Features

With these new Parent/Children features, managing and visualizing many-to-many relations in AppGini is easier, more flexible, and much more user-friendly.

  • Junction tables (like books_authors) appear as related tabs under parent records.
  • You can see, edit, and add related records without leaving the detail view.
  • Table views show child record counts and allow direct addition of new links.
  • Copying parent records can also copy all related (child) records.

These enhancements make AppGini a powerful tool for building business apps that require complex relationships, while keeping data entry and navigation intuitive for end-users.