Skip to content

Conversation

@kbrock
Copy link
Member

@kbrock kbrock commented Jul 24, 2024

relace_virtual_field sometimes returns unnecessary tiers of embedded hashes or arrays. E.g. [[:field]] instead of :field.

6.1 has one fixes, but is by no means exhaustive:

association = association.first if association.kind_of?(Array) && association.size == 1

This fixes replace_virtual_field to not output that value. Since this is at the return of each level, it essentially applied recursively and flattens it significantly.

Added freeze in tests to verify that the input parameter is unmodified.

@kbrock kbrock added enhancement New feature or request rails7 labels Jul 24, 2024
@kbrock
Copy link
Member Author

kbrock commented Jul 24, 2024

update:

  • rubocop: added parens
  • renamed demote_includes to simplify_includes

@kbrock
Copy link
Member Author

kbrock commented Jul 30, 2024

this is now part of #133 - we can merge here or there

@kbrock kbrock force-pushed the empty_includes branch 4 times, most recently from d2b4a45 to 4d62cba Compare July 30, 2024 20:17
@kbrock
Copy link
Member Author

kbrock commented Jul 30, 2024

update:

update:

  • fixed bug introduced by rebase

@jrafanie
Copy link
Member

@kbrock I'm not sure what this fixes. It looks like it fixes a bug but can't envision how this occurs.

In the rails 7.0 migration, I had [[:field]] that I needed to convert into [:field].

Can you describe the problem you had here?

Merged_includes via include_to_hash already promotes classes up to a Hash.
But there was no code that demoted classes back to an array or symbol / nil.

If you look at the changed specs, you can see how this reduces the values.

In the rails 7.0 migration, I was going to add special code to introduce this
but it seems best to do this at the source
@kbrock
Copy link
Member Author

kbrock commented Jul 30, 2024

Hey @jrafanie

ok, I added a pre-commit to this PR.
First commit shows the output with a double array example.
The second commit shows that this example is fixed.

This over optimizes the list for rails 7, and that is why I added the Array[klass_associations] in the preloader - that rubocop did not like.

@miq-bot
Copy link
Member

miq-bot commented Jul 30, 2024

Checked commits kbrock/activerecord-virtual_attributes@153a10f~...a1d7249 with ruby 3.1.5, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
3 files checked, 0 offenses detected
Everything looks fine. 👍

Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

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

Ok, let's get this in and tested with our rails 7 work.

@jrafanie jrafanie merged commit 93053a2 into ManageIQ:master Jul 31, 2024
@kbrock kbrock deleted the empty_includes branch July 31, 2024 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request rails7

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants