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

Prevent duplicate fields in blocklist when using STI #86

Merged
merged 1 commit into from
Sep 26, 2023

Conversation

ethax-ross
Copy link
Collaborator

When the application has models that are configured with single table inheritance the generated blocklist will contain duplicate field names for the table (once for each model).

This is due to the behaviour of attribute_names in Rails; it retrieves the names directly from the table columns and doesn't filter based on the context of the subclass.

To avoid this we need to uniq the attribute names generated for the blocklist.

Example blocklist prior to change (assuming a parent/child using STI):

{:with_model_candidates_43990_9360=>["id", "first_name", "id", "first_name"]}

And after change:

{:with_model_candidates_43990_9360=>["id", "first_name"]}

When the application has models that are configured with single table
inheritance the generated blocklist will contain duplicate field names for
the table (once for each model).

This is due to the behaviour of `attribute_names` in Rails; it retrieves
the names directly from the table columns and doesn't filter based on the
context of the subclass.

To avoid this we need to `uniq` the attribute names generated for the
blocklist.

Example blocklist prior to change (assuming a parent/child using STI):

```
{:with_model_candidates_43990_9360=>["id", "first_name", "id", "first_name"]}
```

And after change:

```
{:with_model_candidates_43990_9360=>["id", "first_name"]}
```
Copy link
Contributor

@ericaporter ericaporter left a comment

Choose a reason for hiding this comment

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

Looks good 👍

@ethax-ross ethax-ross merged commit 6d4e1ea into main Sep 26, 2023
@ethax-ross ethax-ross deleted the prevent-duplicate-fields-in-blocklist branch September 26, 2023 13:16
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.

2 participants