yesodweb / yesodweb/persistent

Can Persistent filter with a comparison on two fields in the same model?

Open
#1,309 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
486
Forks
306
PR merge metrics
No merged PRs in 30d

Description

Hello,

Thank you for such a great library!

I believe I've run into a limitation in persistent, but maybe it's already possible to do this and I'm overlooking how to do it?

I have a model like the following:

Thing
  ...
  fooVal Int
  barVal Int

and I'd like to use selectList with a filter that compares those values such as:

selectThings = runDB $ selectList [ThingFooVal >. ThingBarVal] []

This fails with a type error like:

Couldn't match type 'EntityField Thing Int' with 'Int' arising from a use of ThingBarVal

Is this not possible in persistent directly, or is there a different way I should setup the query?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing Persistent's selectList filter API and the ThingFooVal >. ThingBarVal example to understand how field comparisons are represented. Done means determining whether same-model field comparisons are supported and documenting the supported query path or confirmed limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.