The Craft 6 beta is out. Learn what's new and how Craft 6 works on Laravel. Explore Craft 6

Craft 6: Relationship Columns in Table Fields

Craft 6 adds three relationship column types to the Table field: Entries, Assets, and Users. In this lesson we add them to an existing Table field on a real estate site, configure their sources and limits, select related elements in each row, and see the results on the front end, including what happens when a required cell is left empty. It's a lighter-weight way to add relationships to repeating content without reaching for a Matrix field.

Craft 6 Table fields can now select real entries, assets, and users. The new rela­tion­ship col­umn types first shipped in Craft 6.0.0‑beta.2 (PR #20728).

In this video, I cover:

  • Adding Entries, Assets, and Users columns to an exist­ing Table field
  • The con­fig­ure sheet for each col­umn: sources, an option­al selec­tion con­di­tion, min­i­mum and max­i­mum rela­tions, and the but­ton label
  • Select­ing relat­ed ele­ments in each Table row
  • What hap­pens when a required cell is left empty
  • Out­putting the relat­ed ele­ments on the front end

We start with an exist­ing Table field, List­ing Resources, on the Prop­er­ty entry type of a real estate site. It has a sin­gle plain-text Resource col­umn. From the field’s set­tings we add three new columns:

  • Down­load (Assets): lim­it­ed to the Prop­er­ty Doc­u­ments vol­ume, min­i­mum 1, max­i­mum 1, with an ​“Add a prop­er­ty doc­u­ment” but­ton label. Asset cells select exist­ing files; they don’t upload.
  • Relat­ed Con­tent (Entries): lim­it­ed to the News sec­tion, min­i­mum 1, max­i­mum 1.
  • Own­er (Users): lim­it­ed to the List­ing Resource Own­ers group, min­i­mum 1, max­i­mum 1.

Back on the prop­er­ty entry, each Table row now has ele­ment selec­tors for the three columns. Pick a doc­u­ment, a news entry, and a user, save, and the row keeps real rela­tion­ships, not text labels or copied IDs. Because each col­umn requires exact­ly one selec­tion, leav­ing the Own­er cell emp­ty stops the save with ​“One or more table cells con­tained invalid values.”

On the front end, the prop­er­ty page lists each resource row with its relat­ed news arti­cle, its PDF down­load, and its own­er. Add more rows and each one gets its own set of relationships.

Table fields have always been fine, but lim­it­ed to sim­ple val­ues. With rela­tion­ship columns, you can mod­el repeat­ing rows of relat­ed con­tent with­out deploy­ing a Matrix field. Craft 6 is still in beta, so check your installed release before using this on a project.

Find all of the Craft 6 videos at craftquest.io/craft‑6.

Transcript

Premium

Follow along with the full transcript

Search every word, click any line to jump to that moment, and read along as you watch. A CraftQuest Premium feature.

Sign up for Premium