yesodweb / yesodweb/persistent

Allow intentionally defining an `id` field

Open
#1,016 2 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

I would like to allow defining the following:

User
    id Int64
    ...
    Primary ...
  • This should suppress all the existing magic such as generating a UserId type.

  • UserId would be an EntityField User Int64.

  • The User type would include a userId :: Int64 field.

  • All the Key-based stuff would be based on the Primary field.

As I have used persistent more and more, I have noticed that a lot of the pain points are either due to not being able to treat regular fields more like id, or due to not being able to treat id more like a regular field. So I would like to slowly unify id with other fields in a backwards compatible way.

This change in isolation is less useful than it will be after changes like #995 are implemented, but I similarly think that #995 is less useful without this change. So I think it makes sense to implement this first in isolation.

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

No files or tests are named in the issue. Start by tracing how Persistent currently handles generated IDs, EntityField types, user record fields, and Primary/Key behavior, then compare the desired model with the related changes in #995. Done means intentionally defining an id field works without the existing generated-ID magic while preserving backwards compatibility.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.