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

Rails/WhereExists allowing where + exists on multi-line chain #1331

Open
chulkilee opened this issue Aug 14, 2024 · 0 comments
Open

Rails/WhereExists allowing where + exists on multi-line chain #1331

chulkilee opened this issue Aug 14, 2024 · 0 comments

Comments

@chulkilee
Copy link

Is your feature request related to a problem? Please describe.

If there is multiple (especially) multiline where, merging only the last into exists doesn't improve the readability.

Example

User
  .joins(:profile)
  .where(profile: { kind: "bar" }
  .where.not(attr1: "foo")
  .where(attr2: "bar")
  .exists?

Currently it enforces

User
  .joins(:profile)
  .where(profile: { kind: "bar" }
  .where.not(attr1: "foo")
  .exists?(attr2: "bar")

Describe the solution you'd like

Allow exists at the end of multi-line chain, even after .where

Describe alternatives you've considered

I may merge some where clauses, but not all of them (e.g. with not for instance) - so having both where and exists? looks strange to me.

# group all possible where (except not)
User
  .joins(:profile)
  .where.not(attr1: "foo")
  .exists?(profile: { kind: "bar" }, attr2: "bar")

# put joins and related where at one line
User
  .joins(:profile).where(profile: { kind: "bar"})
  .where.not(attr1: "foo")
  .exists?(attr2: "bar")

Also.. I prefer to have single exists? over where.exists? for simple cases, so using EnforcedStyle: where is not an option for me.

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

No branches or pull requests

1 participant