yesodweb / yesodweb/persistent

ID fields can sometimes be generated with ForeignRefs

Open
#1,615 0 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

For example:

ExplicitPrimaryKey sql=explicit_primary_key
    Id Text

produces an EntityDef of

    EntityDef
        { entityHaskell = EntityNameHS{unEntityNameHS = "ExplicitPrimaryKey"}
        , entityDB = EntityNameDB{unEntityNameDB = "explicit_primary_key"}
        , entityId =
            EntityIdField
                ( FieldDef
                    { fieldHaskell = FieldNameHS{unFieldNameHS = "Id"}
                    , fieldDB = FieldNameDB{unFieldNameDB = "id"}
                    , fieldType = FTTypeCon Nothing "Text"
                    , fieldSqlType = SqlString
                    , fieldAttrs = [FieldAttrOther "Text"]
                    , fieldStrict = False
                    , fieldReference =
                        ForeignRef (EntityNameHS{unEntityNameHS = "ExplicitPrimaryKey"})
                    , fieldCascade = FieldCascade{fcOnUpdate = Nothing, fcOnDelete = Nothing}
                    , fieldComments = Nothing
                    , fieldGenerated = Nothing
                    , fieldIsImplicitIdColumn = True
                    }
                )
        , [...]
        }

I would expect fieldReference = NoReference here - it doesn't really make sense for an entity's ID field to be a reference to itself.

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 locating the code that generates EntityDef values for implicit ID fields and reproducing the ExplicitPrimaryKey example from the issue. Trace why the ID receives a ForeignRef to its own entity; done means the generated fieldReference is NoReference for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.