Skip to content

Add support for default predicates#1384

Merged
scarroll32 merged 2 commits intoactiverecord-hackery:mainfrom
p8:features/default-predicate
Jan 29, 2023
Merged

Add support for default predicates#1384
scarroll32 merged 2 commits intoactiverecord-hackery:mainfrom
p8:features/default-predicate

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.

2 participants