Relationships between tables, and what happens when you delete
Every relationship in Parsware is one-to-many, made by a lookup, and read as many-to-one from the other end. Here is how to see both directions, how to model many-to-many, and why a record that others still point at can't be deleted.

In the lookups article we gave each training course a Trainer, and saw that adding the lookup also created a relationship between Contact and Training Course. This article is about relationships themselves: which kinds there are, how to read them from either table, and what happens to the linked records when one of them is deleted.
We carry on with the same Training Course and Contact tables. Every picture is the real product.
One kind of relationship, read from both ends
Parsware has one kind of relationship: one-to-many. One contact trains many courses, and each course has one trainer. The lookup field sits on the "many" side, on the course.
Many-to-one isn't a second kind. It's the same relationship read from the other end: from a course, the trainer is many-to-one. So a relationship shows up on the Relationships page of both tables. Here is Contact's:

Read each row left to right, from Referenced (one) to Referencing (many):
- In the first three rows Contact is the one. A contact can have many assets assigned to them, book many courses, and train many courses.
- In the last row Contact is the many. Each contact belongs to one company, an account, through its company lookup. That's many-to-one from where we're standing.
The Lookup field column says which field carries the link. It's always on the many side, so to change a relationship you change that field.
Many-to-many: a table in the middle
A course has many attendees, and a person attends many courses. No single lookup can hold that, because a lookup holds one record. The answer is a table in the middle, with one row for each link: an Enrolment table with a Course lookup and an Attendee lookup.
This is two one-to-many relationships, and it's how the platform models its own many-to-many links. The Team Membership table in every environment is exactly this, one row for each user in each team. The table in the middle is also where the link's own details go: the date someone enrolled, whether they attended, the grade they got. A hidden join table would have nowhere to put those.
Each side then gets a Related tab for free. A course lists its enrolments, and so does a contact.
What happens on delete
A plain lookup comes with a foreign key in the database. That key decides what a delete may do, and the rule is short: you can't delete a record while other records still point at it.
Deleting from the many side is always fine. Delete a course, and its trainer is untouched. The course pointed at the contact, not the other way round.
Deleting from the one side is refused while something points at it. Riley Miller trains two courses and has two assets assigned. Select Riley in the Contacts list, choose Delete, confirm, and the delete is refused:

The message names every table that still points at Riley, and the lookup it points through. Riley's record is still there, and nothing else changed either: the refused delete is undone as a whole.
To go ahead, open Riley's record and use its Related tabs, which list exactly those courses and assets. Give each course another trainer and each asset to someone else, or delete them, then delete Riley.
Parsware doesn't delete the courses for you, and it doesn't quietly empty their Trainer field. Both would lose information. A course with no trainer is a question nobody asked, and it's found weeks later. There's no setting that changes this. If records should really go together, delete the related ones first, on purpose.
A lookup to several tables is different. One lookup that points at several tables can't have a foreign key, because one column can't reference two tables. So the database doesn't stop the delete. The course keeps the reference, and shows it raw instead of a name, so the gap is visible. If you need the delete to be refused, use a plain lookup.
Deleting a whole table
The same rule applies one level up. A table can't be deleted while another table has a lookup to it. Choose Delete from environment on Contact, and instead of a confirmation you get the list of what depends on it:
Lookups to several tables that list Contact block it too, and so do apps that show it in their navigation. Remove or change those first. Nothing is deleted until the list is empty.
A worked example: the training business
Relationships are easiest to get right on paper, before any table exists. Here is the whole model for the training business this series has been building, with an arrow from each lookup to the table it points at:
Account <── company ─── Contact <── trainer ─── Training Course
^ ^ ^
│ │ │
└──── booked by ─────────┴──── booked by ───────────┘ (one lookup to two tables)
Contact <── attendee ── Enrolment ── course ──> Training Course
(enrolled on, attended, grade)
Read it one arrow at a time, and each says many of these, one of those:
- Many contacts work for one account, through company.
- Many courses have one trainer, through trainer.
- Each course is booked by one account or one contact, through booked by, which is one lookup to two tables.
- Many enrolments belong to one course, and many enrolments belong to one attendee. Together those two make the many-to-many: a course has many attendees, an attendee takes many courses.
Drawn like this, the questions that matter answer themselves. Where does the grade go? On the enrolment, because a grade belongs to one person on one course. Where does the trainer's day rate go? On the contact, if it is the same for every course, or on the course if it isn't.
Building the table in the middle
The Enrolment table is an ordinary table with two lookups and whatever the link needs to say about itself. As a document:
{
"logicalName": "con_enrolment",
"displayName": "Enrolment",
"displayCollectionName": "Enrolments",
"publisherPrefix": "con",
"primaryField": "con_name",
"fields": [
{ "logicalName": "con_name", "displayName": "Enrolment",
"dataType": "Text", "maxLength": 200, "isRequired": true, "isPrimary": true },
{ "logicalName": "con_course", "displayName": "Course",
"dataType": "Lookup", "targetEntity": "con_trainingcourse", "isRequired": true },
{ "logicalName": "con_attendee", "displayName": "Attendee",
"dataType": "Lookup", "targetEntity": "contact", "isRequired": true },
{ "logicalName": "con_enrolledon", "displayName": "Enrolled on",
"dataType": "DateTime", "defaultControl": "Date" },
{ "logicalName": "con_attended", "displayName": "Attended", "dataType": "Boolean" }
]
}
Saving it creates two relationships, one to each table, and each table gets a Related tab listing its enrolments. On a course, New on that tab opens an enrolment with the course already filled in, so enrolling five people is five quick forms without leaving the course.
To stop the same person being enrolled on the same course twice, add a rule that the pair must be unique. No duplicates, no double bookings shows how.
Questions across a relationship
A relationship isn't only for forms. Everything that reads data can follow it.
- A view of courses can show the trainer's name, and filter on the trainer.
- A saved query can join the two tables, for example enrolments, with each course's start date and each attendee's company, and total them. Design a query builds one.
- A report can group the enrolments by course and count them, which is the attendance sheet a trainer prints. Groups and totals shows the grouping.
- A script can read the record at the other end with
getRecord, or every record pointing at this one with a query. Query records from a script has both, including a join.
When you really do want to delete everything
The delete rule protects you from losing information by accident. Sometimes you mean it: a test course with its enrolments, or a customer who asked to be forgotten. Do it in the order the arrows point, from the many side up.
- Open the record and look at its Related menu. Every table listed there has records pointing at it.
- Open each related tab and decide, row by row or by selecting several: give them to another record, or delete them.
- When the Related tabs are empty, delete the record. It goes through now, because nothing points at it.
If the delete is still refused, read the message again. It names every table and lookup that holds the record, including ones that aren't on the form you are using.
Relationships travel with their lookups
There is nothing separate to add to a solution. A relationship belongs to the lookup that makes it, and the lookup belongs to its table, so exporting the table exports the relationship. On import, the platform checks that the table at the other end exists in the target environment, either in the same package or already installed. If neither, the import stops before creating anything.
That matters when one solution extends another's tables. A lookup from your Training Course to the platform's Contact imports anywhere, because every environment has Contact. A lookup to a table from another of your solutions needs that solution imported first. Several solutions in one environment covers the order.
Name lookups for the people at the other end
A lookup's display name is read in two places: on the form that holds it, and in the Related menu of the table it points at. When a table has two lookups to the same table, the Related menu tells them apart by the lookup's name, as Training Courses (con_trainer) and Training Courses (con_bookedby) showed in the lookups article.
So name a lookup for the role the other record plays, not for its table:
| Instead of | Name it | Because |
|---|---|---|
| Contact | Trainer, Attendee, Booked By | A table can point at Contact for several reasons |
| Account 1, Account 2 | Supplier, Customer | The names should say which is which a year from now |
| Parent | Parent category, Reports to | A lookup to its own table is clearer with the role spelled out |
The logical name follows the display name when you create the field, so a good display name gives you a good logical name too, and it is the logical name that appears in the brackets.
Questions that come up
Can I add a relationship without a lookup? No. The lookup is the relationship. Add the lookup field and the relationship comes with it.
Can I rename a relationship? Its name is made from the table and the lookup field, so it changes only if they do, and their logical names are fixed. The display names people read can change at any time.
Why can't the database just delete the related records for me? Because it would delete things nobody looked at. A contact who trains two courses is a reason to stop and think, not a reason to lose two courses. The message tells you exactly what to look at.
In short
- Every relationship is one-to-many, made by a lookup on the "many" side. Many-to-one is the same relationship, read from the other table.
- Many-to-many is a table in the middle with two lookups, and it can hold details about each link.
- A record other records point at can't be deleted. The message names each table and lookup that still holds it. Deleting from the many side is always allowed.
- A lookup to several tables has no foreign key, so it doesn't block a delete.
- A table can't be deleted while a lookup, or an app, still depends on it.
Next: option sets, reusable choice lists with their own colours and icons.