Skip to content

Enum should allow the conventionally case-sensitive operators#434

Merged
jkeen merged 2 commits into
graphiti-api:masterfrom
jasonkarns:patch-2
Mar 18, 2024
Merged

Enum should allow the conventionally case-sensitive operators#434
jkeen merged 2 commits into
graphiti-api:masterfrom
jasonkarns:patch-2

Conversation

@jasonkarns

Copy link
Copy Markdown
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

jkeen commented Feb 27, 2024

Copy link
Copy Markdown
Collaborator

@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

jkeen commented Feb 27, 2024

Copy link
Copy Markdown
Collaborator

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
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))
@github-actions

Copy link
Copy Markdown

🎉 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.

2 participants