Ask A Question

Notifications

You’re not receiving notifications from this thread.

Single Table Inheritance (STI) with ActiveRecord in Rails Discussion

Thanks Chris, It's funny that we just stopped using this design pattern at Gitlab

https://docs.gitlab.com/ee/development/database/single_table_inheritance.html

Reply

Thanks for the episoded Chris!

What would you say are the main use cases that can benefit from STI ?

Reply

Delegated types next! 🤘🏻

Reply

Nice! I used STI for an app with all types of documents, and I used the jsonb_accessor gem. It allows you to query the json fields just as if it were an active record column.

so my documents had just four columns but within the json column the table really looked more like this...






And I could just say InsuranceDocument.account_id even though it was technically InsuranceDocument.customData["account_id"]

I'm interested in delegated types as well.

Reply

At 2:34 the migration don't have foreign_key: true for t.belongs_to :event, null: false. What impact that make to not mention that?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 81,149+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2024 GoRails, LLC. All rights reserved.