One of APIgoat’s most powerful and time-saving features is its parent/child relationship management, allowing you to build comprehensive interfaces effortlessly—without writing code.
A parent/child relationship defines how one entry (the parent) can hold a collection of related entries (the children) from a different model. For example, a Person can have multiple Addresses, ranging from zero to an unlimited number.
APIgoat automatically generates intuitive interfaces to manage these relationships, such as displaying a list of addresses within a Person form. Additionally, many-to-many relationships are fully supported, making complex data handling seamless.
HJSON
Foreign key
To create the relationship in the database,
"id_person":["integer()","foreign(person)",'not-required', 'default:null']
foreign(person) assume that the primary key in the table person is the same name: id_person.
If you need to change that, simply add ,”foreign:person_id”
Parent / child
To create the interfaces, you need one one or multiple parameters: set_parent_table, with_child_tables.
"set_parent_table": 'group',
This would be added to the Person table, who is a Child of Group. This is not mandatory as with_child_tables will detect parents and make sure that the parent is always set when creating a child in the parent interface.
"with_child_tables": ["person"],
This would be added to the Group table, who is a Parent of Person.
"group('Group')": { set_menu_priority: 1, "with_child_tables": ["person"], "id_group()": ["primary()"], "name('Name')": ["varchar(100)"], "validator": {"name":{"required":{"msg":"name_required","value":null}}}, }, "person('Person')": { "id_person()": ["primary()"], "name('Name')": ["varchar(100)"], "id_group":["integer()","foreign(group)",'not-required', 'default:null'] "validator": {"name":{"required":{"msg":"name_required","value":null}}}, }
Now, once you create a Group (Group/edit/), the child section will appear:


Note again that the Group is note in the form. It will be set automatically.
Menu
Make sure to add menu items. By default, the routes are created, but its up to you to define your menu. Use one of there for menu and submenu:
set_menu_priority: 100,
set_parent_menu:"Settings",
Child/Foreign display
set_child_colunms:{"id_creation":["username"]}
In the case you want to force the referred table column display, use `set_child_colunms`. You can set one or multiple column to display in forms and lists.