yesodweb / yesodweb/persistent

foreign primary key to foreign primary key

Open
#806 1 comment 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

In the below example (disregard User, its just a simple auto incremnt entity) i want to express GroupTopicMember's pk is a foreign key to GroupTopic that in turn has pk that is a foreign key to ChatTopic. It needs to be that chain cause there can be no GroupTopicMember if theres no GroupTopic. When compiling this program i get

• Not in scope: type constructor or class ‘ChatTopicId’


ChatTopic
  ct_name String sql=name
  deriving Show Eq Generic

GroupTopic
  pcm_topicId ChatTopicId sql=topic_id
  Primary pcm_topicId
  deriving Show Eq Generic

GroupTopicMember
  prtm_userId UserId sql=user_id
  prtm_topicId GroupTopicId sql=topic_id
  Primary prtm_userId prtm_topicId
  deriving Show Eq Generic

...as if its not yet aware of ChatTopicId when it tried to construct the GroupTopicMemberKey? If i change prtm_topicId to ChatTopicId it compiles but the resulting migration created foreign key goes from GroupTopicMember to ChatTopic - which is not correct association. Im using mysql, if that explains anything. (Note, there are more "xyz-chat-topic" entities not shown here - but these have direct association to ChatTopic and doesnt have associated entities, so works wo problem. ChatTopic is conceptually a sumtype, but dont know if I could model such using Persistent)

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

The supplied ChatTopic, GroupTopic, and GroupTopicMember definitions are the reproduction; start by compiling them with the MySQL backend and inspecting the generated migration. Done means the chained primary-key model compiles and the resulting foreign key points from GroupTopicMember to GroupTopic.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.