I’m using this feature in an application that has a variety of similar models—where the models are similar I’ve created concerns that implements logic for each type of similarities models might share (like Appable
, Databasable
, etc.).
Where alias_association
really shines is when I need to define some generic relationship; for example in a Databasable
model I might use alias_association :server, :postgres_server
. From the concerns it’s then easy to do some magic such as database.server.online?
instead of having to determine the correct relationship at runtime.
Not having a feature that allows this built into Rails beyond version 7.0 has blocked our ability to move on. It’s simply too taxing to break down each part of code that uses syntax like this, and I find it personally undesirable to write 3-4 different implementations depending on the models involved.
I hope my insight provides a reasonable use case for the feature.