---
title: "Comment by chaadow on \"A Pattern for STIs in Rails\" | Hashnode"
description: "Could we go an extra mile and delay eager loading until some model in the hierarchy is loaded? Perhaps. Maybe Rails includes something like this in the future i"
url: "https://hashnode.com/posts/a-pattern-for-stis-in-rails/635fe4da982ebb40a7eaa15d/comment/636147467c8ae671518e0e9c"
---

[Discussion](https://hashnode.com/posts/a-pattern-for-stis-in-rails/635fe4da982ebb40a7eaa15d)

Comment [A Pattern for STIs in Rails](https://hashnode.com/posts/a-pattern-for-stis-in-rails/635fe4da982ebb40a7eaa15d)

[chaadow](https://hashnode.com/@chaadow)

[Nov 1, 2022](https://hashnode.com/posts/a-pattern-for-stis-in-rails/635fe4da982ebb40a7eaa15d/comment/636147467c8ae671518e0e9c)

> Could we go an extra mile and delay eager loading until some model in the hierarchy is loaded? Perhaps. Maybe Rails includes something like this in the future if we find an even better technique, we'll see.

Can't we use something like `Rails.autoloaders.main.on_load('MyModel') { ... }` ?

This can be useful when applying the strategy pattern, in the same vein as having a `_sti` as a suffi, a team can use a `xxxBase` suffix.

Which makes me want to ask you this question: Can we use a regular expression with the `on_load` hook?. This in combination with the `_sti` prefix idea, we can eager load a directory if it exists.

Basically the `Base` class will act as a router, look through the descendants and return the first applicable strategy class ( like ActiveJob::Serializers does )

Do you think this is feasible? Thanks for the article!

[Xavier Noria](https://hashnode.com/@fxn)

[Dec 10, 2022](https://hashnode.com/posts/a-pattern-for-stis-in-rails/635fe4da982ebb40a7eaa15d/comment/636147467c8ae671518e0e9c#reply-6394cdbc9fa713176ab9cb8f)

[chaadow](https://hashnode.com/@chaadow) Sorry, I got no notification for these comments!

That is a good idea and a version of that was documented. Problem is that it may lead to unsolvable circular dependencies that depend on load order. I am revamping the section in the guides about this topic.
