Loading...
edit-examples

Linked Records with Cascade

Linked Records with Cascade adds on_delete behavior to existing reference fields so parent deletes either remove children, block deletion, or clear optional links. Use it to keep linked records consistent without hand-editing plugin files.

Trusted by frontline teams 15 years of frontline software

Built for: Professional Services · Operations · Finance · Software · Internal Tools

Overview

Linked Records with Cascade is an edit-mode template for apps that already use reference fields and need explicit delete behavior. It scans the plugin’s record schemas, identifies each reference field, and adds the right on_delete rule in plugin.rb: cascade for owned children, restrict for required children, and nullify for optional links.

Use this template when your app has parent-child records and you want deletions to behave predictably instead of relying on manual cleanup. It is a good fit for linked records such as projects and tasks, invoices and line items, or posts and tags where the relationship type changes how deletion should work. The template also adds a user-facing message on the parent show page so people can see what will happen before they delete.

Do not use this template as a generic data-model builder or for brand-new apps with no existing references. It is also not the right choice if you need a full workflow engine, approval system, or complex archival logic. The goal here is narrower: make existing links safe by encoding delete rules directly in the field definitions and surfacing that behavior in the UI.

How to use this template

  1. Review the existing record schemas and list every reference field that links one record type to another.
  2. Decide for each link whether the child is owned, required, or optional, and map that to cascade, restrict, or nullify.
  3. Update the reference field declaration in plugin.rb with the correct on_delete option for each field.
  4. Add or edit the parent show page message so users can see what happens when they delete the parent record.
  5. Run the app with sample data, delete a parent record, and confirm that each relationship behaves as intended.
  6. Fix any mismatches between the data model and the delete rule before shipping the plugin.

Best practices

  • Treat every reference field as a separate decision instead of copying one on_delete rule across the whole plugin.
  • Use cascade only for records that truly have no meaning without the parent, such as owned line items or child tasks.
  • Use restrict for records that must remain attached to a parent, because it prevents accidental orphaning and data loss.
  • Keep optional links as nullify when the child should survive without the parent relationship.
  • Add a clear delete warning on the parent show page so users understand the effect before they confirm the action.
  • Test deletes with realistic sample data, including parents that have multiple children and parents with no children.
  • Check for downstream references before choosing cascade, since deleting one parent can remove records other screens still expect to exist.

What this template typically catches

Issues teams running this template most often surface in practice:

Parent deletes leave orphaned child records because the reference field had no explicit on_delete rule.
A required child record is left behind with a broken link because the default behavior was treated as safe.
Users do not know what delete will do because the parent detail screen gives no warning.
Different reference fields in the same plugin behave inconsistently because each one was handled manually.
Spreadsheet-era cleanup steps are forgotten, so linked records accumulate in an invalid state.
The app blocks deletions too late, after users have already started a destructive action.
Optional relationships are overprotected, causing unnecessary delete failures instead of simple link removal.

Common use cases

Project management plugin
A project record owns task records, so deleting the project should cascade to its tasks. Optional assignee or contact links can remain nullify so the task still exists if the link is removed.
Invoice and billing plugin
An invoice owns its line items, so line items should disappear with the invoice rather than remain as orphaned rows. Required payment or approval links can use restrict if the parent should not be deleted while dependent records exist.
CRM deal records
A deal may reference contacts, tags, or optional account links that should clear when the parent is removed. This template helps separate those optional links from owned records that should be deleted together.
Internal operations admin tool
An operations team maintaining linked records in a plugin can standardize delete behavior across several reference fields. The parent show page message gives staff a clear warning before they remove a record.

Frequently asked questions

What does this template change in my app?

It updates existing reference fields in plugin.rb so each link has an explicit on_delete rule. The template covers cascade for owned children, restrict for required children, and nullify for optional links. It also adds a user-facing note on the parent show page so delete behavior is visible before action.

When should I use cascade versus restrict versus nullify?

Use cascade when the child record only makes sense as part of the parent, such as tasks under a project or line items under an invoice. Use restrict when deleting the parent would leave invalid or broken child records. Use nullify when the relationship is optional and the child can continue without the parent link.

Does this template create new records or screens?

No. It is an edit-mode template that changes existing reference field declarations and adds a delete-behavior message on the parent detail screen. It is meant for apps that already have linked records in place and need safer deletion rules.

Who should run this template?

A builder or admin who understands the record model and can tell which relationships are owned, required, or optional. It is especially useful when a plugin already has several reference fields and you want to avoid accidental orphaned data or unsafe deletes. If the data model is unclear, review the relationships before applying the change.

What is the main pitfall when setting on_delete rules?

The most common mistake is marking a relationship as cascade when the child should be preserved, or restrict when users expect cleanup to happen automatically. Another pitfall is leaving the default nullify behavior on a required link, which can create orphaned records. The template is designed to force each reference field to be reviewed one by one.

How does this help compared with handling deletes manually?

Manual delete handling usually depends on someone remembering the right steps every time, which is easy to miss in spreadsheet-era workflows. This template puts the rule in the field definition itself, so the app enforces the same behavior consistently. That reduces orphaned records, broken links, and support issues after deletions.

Can I customize which fields use cascade or restrict?

Yes. The template is meant to be adjusted to your specific record relationships, not applied blindly. You can keep optional links as nullify, switch owned children to cascade, and use restrict where deletion should be blocked until dependent records are handled.

Does this integrate with existing plugin files and UI text?

Yes. The prompt explicitly updates the reference field declarations in plugin.rb and adds a delete explanation on the parent show page. It also asks for small, targeted edits only, which makes it easier to fit into an existing plugin without rewriting unrelated files.

What should I check before rolling this out?

Review every reference field and confirm the intended lifecycle of the child record. Test deletes on a copy of the app with real-looking sample data so you can see whether cascade, restrict, or nullify behaves as expected. Also verify that the parent show page message matches the actual rule users will experience.

Go deeper on the topic

Related concepts
  • A daily huddle is a brief (10–15 minute) standing meeting held at the start of a shift or workday to align the team on priorities, surface issues, and...
  • A deskless worker is any employee whose job happens without a desk, a company laptop, or a fixed workstation. They're roughly 80% of the global workforce —...
  • A frontline employee app is a phone-first application that gives hourly, field, and deskless workers access to their schedule, pay, announcements, training,...
  • A frontline worker is any employee whose job happens away from a desk — on a production floor, in a patient room, behind a store counter, in a customer's...
Related guides

Ready to use this template?

Get started with MangoApps and use Linked Records with Cascade with your team — pricing built for small business.

Get Started