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

Remove relationships key when having fields with no relationships specified #206

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

Conversation

ABraconnier
Copy link

@ABraconnier ABraconnier commented Dec 16, 2021

What is the current behavior?

The fields option was filling the relationships_hash with an empty hash instead of not having it at all:

        relationships = relationships.slice(*fieldset) if fieldset.present?

But you can have some cases where you do have fieldsets but none of those fieldsets are related to the relationships. Instead of having no relationships at all, you will have then an empty hash, even though if you specifically specified you didn't want and relationships in your fields option.
See issue : #167

What is the new behavior?

IF there is a fieldset but that fieldset has no keys related to the relationships, the relationships_hash will return nil and will not be constructed.
IF there is a field with some keys related to the relationships, those keys will slice relationships_to_serialize to select the ones related
IF there is no fieldset, all the keys of the relationships are selected

Checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes /
    features)
  • All automated checks pass (CI/CD)

Disclaimer

This the first time I'm posting a PR for open source gem, but I'm doing my best! Looking forward for review / things to change.

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