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

Enum should allow the conventionally case-sensitive operators #434

Merged
merged 2 commits into from
Mar 18, 2024

Conversation

jasonkarns
Copy link
Contributor

By default (ie, for strings), eq is a case-insensitive match and eql is case-sensitive.

string_enum is documented as being "like string but only with case-sensitive eq/not_eq operators".

These two statements feel like contradictions to me. If string_enum is basically like string but always does case-sensitive filtering, then shouldn't it support the existing case-sensitive operator?

Some more rationale why I think this should be the case:
polymorphic associations have a discrete list of possible values for the as_type attribute. So to me it's only natural that the as_type attribute be defined as a string_enum. (strict case matching!)

However, using the polymorphic_has_* helpers results in an relationship filter using the eql (case-sensitive) operator. So we have an attribute type that expects to be matched strictly; and a relationship filter that matches strictly. But the two are incompatible! (because string_enum only defines eq operator, and polymorphic_has_* helpers define eql operator; despite both ostensibly wishing to compare strictly case-sensitve.)

So this PR proposes that the enum types also define eql operators (which are already expected to be case-sensitive for strings) essentially as duplicates of the existing eq operators. Doing so will allow polymorphic as_type attributes to be defined as string_enum and still leverage the eql filter applied by the polymorphic_has_* helper.

Warning no tests yet. This PR primarily for discussion.

@jkeen
Copy link
Collaborator

jkeen commented Feb 27, 2024

@jasonkarns I just hopped into the ring to get this project back up to speed, and what you said makes sense to me. Would you mind adding some tests for it?

@jkeen
Copy link
Collaborator

jkeen commented Feb 27, 2024

Related to #403

jasonkarns and others added 2 commits March 18, 2024 10:00
By default (ie, for strings), `eq` is a case-insensitive match and `eql` is case-sensitive.

`string_enum` is documented as being "like string but only with case-sensitive `eq`/`not_eq` operators".

These two statements feel like contradictions to me. If `string_enum` is basically like `string` but always does case-sensitive filtering, then shouldn't it support the existing case-sensitive operator?

Some more rationale why I think this should be the case:
polymorphic associations have a _discrete list_ of possible values for the as_type attribute. So to me it's only natural that the as_type attribute be defined as a `string_enum`. (strict case matching!)

However, using the polymorphic_has_* helpers results in an relationship filter using the `eql` (case-sensitive) operator. So we have an attribute type that expects to be matched strictly; and a relationship filter that matches strictly. But the two are incompatible! (because string_enum only defines `eq` operator, and polymorphic_has_* helpers define `eql` operator; despite both ostensibly wishing to compare strictly case-sensitve.)

So this PR proposes that the enum types _also_ define `eql` operators (which are already expected to be case-sensitive for strings) essentially as duplicates of the existing `eq` operators. Doing so will allow polymorphic as_type attributes to be defined as string_enum and still leverage the `eql` filter applied by the polymorphic_has_* helper.

**Warning** no tests yet. This PR primarily for discussion.
@jkeen jkeen merged commit 56d34fd into graphiti-api:master Mar 18, 2024
36 checks passed
github-actions bot pushed a commit that referenced this pull request Mar 18, 2024
## [1.5.2](v1.5.1...v1.5.2) (2024-03-18)

### Bug Fixes

* Enum should allow the conventionally case-sensitive operators ([#434](#434)) ([56d34fd](56d34fd))
Copy link

🎉 This PR is included in version 1.5.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

jkeen added a commit to jkeen/graphiti that referenced this pull request Mar 27, 2024
…raphiti-api#434)

Add eql and not_eql operators to enum for case-sensitive matching, aligning with string behavior and improving polymorphic association ergonomics

---------

Co-authored-by: Jeff Keen <jeff@keen.me>
jkeen pushed a commit to jkeen/graphiti that referenced this pull request Mar 27, 2024
## [1.5.2](graphiti-api/graphiti@v1.5.1...v1.5.2) (2024-03-18)

### Bug Fixes

* Enum should allow the conventionally case-sensitive operators ([graphiti-api#434](graphiti-api#434)) ([56d34fd](graphiti-api@56d34fd))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants