Use an Entity Diagram to Draft a Data Model for a Rails App, Part 2: Application Objects for D&D @StatelessCode
Use an Entity Diagram to Draft a Data Model for a Rails App, Part 2: Application Objects for D&D  @StatelessCode
Uploaded January 2025 | Updated November 2026, 3 days ago
Dungeons & Dragons is a complex game with a lot of rules and data. In this video, we build upon the foundation of the previous video and try to build a data model that we can use for our Rails app.

Many of the rules and features in D&D are "polymorphic". Your character could be granted resistance to fire damage, but that feature could be granted by a variety of different sources (race, class, sub-class, magic item, spell, epic boon). The name of the feature as granted by the source may vary, but the mechanics of it are the same. To represent this we added a couple of tables called features and rule_features. Both of those tables are polymorphic. A feature could grant proficiency in skills, tools, weapons, or armor. It could allow you to learn a spell.

By the time we get done, the entity diagram kind of looks like a conspiracy board. There are some pretty complex relationships and associations between the different D&D entities.

At the end, we ask, do we still want to prioritize this project? In real life, 15 months elapsed from when the video was started until its completion. We'll discuss this in our next retrospective.

This video covers:
00:00:00 Introduction and recap of the previous video
00:04:26 Create profiles table
00:11:06 Take a look at a character sheet and talk about how we would represent it in our entity model
00:17:33 Review iteration of data model with campaign settings, campaigns, and campaign members
00:23:00 First attempt at characters table
00:25:59 Add in races, features and rule features tables
00:32:22 Review polymorphic relationships in the Rails Guides
00:35:23 Add polymorphic relationships to features (tools, languages, skill proficiencies, weapon types, armor types)
00:41:26 Review finished initial draft of entity model

#ruby #rails7 #rails #rubyonrails #rubygems #codecast #screencast #github #opensource #minitest #TDD #agile #NerdDice #DnD #roleplaying #softwaredevelopment #learntocode #tailwind #postgresql #rubocop #devise #turbo #controllers #views #activerecord #migrations #entitydiagram #datamodeling #orm #drawio

See other related StatelessCode videos:
- Use an Entity Diagram to Draft a Data Model for a Rails App, Part 1: Overview and Users Table youtu.be/ZL-dvU0N3f8

Resources that we relied upon for this solution:
- Dungeons & Dragons 5E (2014 version) character sheet media.wizards.com/2022/dnd/downloads/DnD_5E_CharacterSheet_FormFillable.pdf
- Rails Guides: Active Record Associations guides.rubyonrails.org/association_basics.html (video displays the Rails 7.0 version)
- draw.io app.diagrams.net

Commit with entity diagram:
- github.com/statelesscode/statelesscode/commit/4468095

This video is CC0 - No rights reserved. (YouTube doesn't allow this option when publishing.) All code is released under the UNLICENSE. Stateless Code denies the concept of "intellectual property". Copying is not stealing.
Use an Entity Diagram to Draft a Data Model for a Rails App, Part 2: Application Objects for D&DCodecast: Getting Started with Rails 7 16: Refactor Repeated Code Using ConcernsCodecast: Getting Started with Rails 7 23: Add Styles from CDNs to Improve DesignCodecast: Getting Started with Rails 7 08: Model Validations and Form Error MessagesRemix One of Your Existing Videos into a YouTube ShortCodecast: statelesscode.com WordPress 24: Style the Comment FormCodecast: statelesscode.com WordPress 09: Use Flexbox to Position Sidebar and Add StylingCodecast: Getting Started with Rails 7 09: Update an Article and Use Form PartialsAdd a CONTRIBUTING.md File to the Project to Help with CollaborationCreate a RubyGem 91: Add a Security Policy to the GemCodecast: Getting Started with Rails 7 01: Install, Create Project, and Start ServerInkscape 05: Create Stateless Code Inkscape Logo
Stateless Code |

Use an Entity Diagram to Draft a Data Model for a Rails App, Part 2: Application Objects for D&D

SHARE TO X SHARE TO REDDIT SHARE TO FACEBOOK WALLPAPER