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

Add support for default predicates #1384

Merged
merged 2 commits into from Jan 29, 2023

Conversation

p8
Copy link
Contributor

@p8 p8 commented Dec 19, 2022

Currently predicates are required, otherwise the conditions are ignored or they will raise an error.
When using Ransack for filtering in json requests, it would be nice to allow an empty predicate to equal to true.

So instead of having to explicitly pass '*_eq':

{
  product_id_eq: 'product-1',
  type_eq:       'admin'
}

we can do the following:

{
  product_id: 'product-1',
  type:       'admin'
}

This adds a :default_predicate configuration option that will be used in case of a missing predicate.

I'm not sure anyone would use a different default, so maybe the config option should be something like: :default_to_eq_predicate.

p8 and others added 2 commits December 19, 2022 12:38
Currently predicates are required, otherwise the conditions are ignored
or they will raise an error.
When using Ransack for filtering in json requests, it would be nice to
allow an empty predicate to equal to true.

So instead of having to explicitly pass '*_eq':

    {
      product_id_eq: 'product-1',
      type_eq:       'admin
    }

we can do the following:

    {
      product_id: 'product-1',
      type:       'admin
    }

This adds a `:default_predicate` configuration option that will be used
in case of a missing predicate.
@scarroll32 scarroll32 merged commit fc4b83d into activerecord-hackery:main Jan 29, 2023
@scarroll32
Copy link
Member

Thank you @p8 🚀

@p8
Copy link
Contributor Author

p8 commented Jan 29, 2023

Thanks @scarroll32 !

@p8 p8 deleted the features/default-predicate branch January 29, 2023 14:55
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

2 participants