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

Expand rails-specific relationship detection #799

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

trbgusto
Copy link

I'm not sure if this functionality is of interest to anyone else, but I figured I can share it here and close the PR if it's not something that should be merged. I'm also happy to add some changes if requested/useful.

What

Expand the relation detection for rails naming schemes by supporting custom column names and adding support for UUIDs.

Why

Ruby on Rails doesn't add foreign keys by default, instead relying on a specific naming scheme, which the -rails flag activates. In this scheme, table names are plural and each table has an id column. Child-tables reference the parent-table via "${singularParentTableName}.id", e.g. a table called companies would be referenced as company_id.

It's possible to use custom names for mapping columns in rails, often used to map two columns to two different records in the same parent table. This PR adds support for prefixed column names, e.g. original_company_id and current_company_id would both resolve to companies.id.

We also use UUIDs in some areas in addition to an autoincrementing ID field, and this PR adds support for _uuid suffices.

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.

None yet

1 participant