Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support single table inheritance #77

Merged
merged 2 commits into from
Jun 28, 2023
Merged

Conversation

duncanjbrown
Copy link
Contributor

@duncanjbrown duncanjbrown commented Jun 27, 2023

When apps use single-table inheritance, multiple Rails models share the same database table - i.e. they are considered a single 'entity' by DfE Analytics.

This isn't good, because it means that at most one model can be associated with a single table. In turn this means that we will not know to attach callbacks to the other models in the STI heirarchy. In practice, due to the order in which ActiveRecord::Base.descendants returns the models, this ends up being the alphabetically first child — not the parent, and not any of the siblings.

Added DNM so @JR-G can test it out on Apply first!

Confirmed working on Apply

@duncanjbrown duncanjbrown force-pushed the single-table-inheritance branch from c2cdd79 to 552bd0a Compare June 28, 2023 10:29
@duncanjbrown duncanjbrown changed the title [DO NOT MERGE] Support single table inheritance Support single table inheritance Jun 28, 2023
Copy link
Collaborator

@asatwal asatwal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few rubocop failures that need fixing - Otherwise LGTM 👍

@duncanjbrown
Copy link
Contributor Author

Looks like it's broken on Ruby 2.7/Rails 6.1. I'm going to check whether anyone's even on that stack

@duncanjbrown
Copy link
Contributor Author

oh, it's an order-dependent failure due to spec activerecord trickery — will fix

When apps use single-table inheritance, multiple Rails models
share the same database table - i.e. they are considered a single
'entity' by DfE Analytics.

This isn't good, because it means that at most one model can be
associated with a single table. In turn this means that we will not know
to attach callbacks to the other models in the STI heirarchy. In
practice, due to the order in which ActiveRecord::Base.descendants
returns the models, this seems to be the alphabetically first child, not
the parent, and not any of the siblings.

Treating the right hand side of the mapping as a list of models, not a
single model, allows us to handle this. We have to update the code in
a couple places to expect arrays instead of strings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants