0

Say there is an entity "Awards Ceremony." During an awards ceremony, a "Person" could get one "Award" (or another way of saying it: an award can be given to a person). This is simple enough to model.

However, it is also possible for a "Person" to be given multiple "Awards". Or an "Award" could be shared among multiple "Persons". This is where I am struggling with the modeling. I feel that I need at least 3 tables: Award Ceremony, Person, Award. Then I think I need a mapping table to correctly model how the Person entity might have multiple Award, or the Award might have multiple Person.

Any suggestions on how to model this?

I'm using MySQL. Also using Laravel's Eloquent ORM.

EDIT 1:

I think this is how it can be modeled:

award_ceremony
 - id
 - name

person
- id
- name

award
- id
- name

mapping
- id
- award_ceremony_id
- person_id
- award_id

It's the mapping table I'm not sure of.

4

3 回答 3

4

你在正确的轨道上。您所需要的只是一个和之间的交集表(多对多)表,Award如下Person所示:

在此处输入图像描述

Recipient表允许多人共享奖励。它还允许一个人赢得多个奖项。当然,它也允许一个人获得奖项。

请注意,Recipient不需要它自己的id,主键是和Recipient的外键组合。此外,没有理由拥有外键,因为关系 to已经暗示了这种关系。AwardPersonAward_CeremonyAward

编辑:表格和列...

您可以像这样使用表/列定义:

award_ceremony
 - id (PK)
 - name

person
- id (PK)
- name

award
- id (PK)
- name
- award_ceremony_id (FK)  // This belongs here!

recipient
- person_id (PK, FK)
- award_id (PK, FK)
于 2013-09-29T12:23:59.870 回答
0

我添加了解决方案,您的架构未完全标准化。我也喜欢添加收件人实体的想法之一,但要进行修改。检查下面这两个。

解决方案:1

    Ceremony
        -ID
        -NAME
    PK = (ID)
    Unique= (Name)

    Person
        -ID
        -NAME
    PK = (ID)
    Unique= (Name)

    Award
        -ID
        -NAME
    PK = (ID)
    Unique= (Name)


    AwardOwner
        -AwardOwnerID
        -AwardID        =fk TO Award.ID
        -OwnerID        =fk TO Person.ID
        -CeremonyID     =fk TO Ceremony.ID
    PK = (AwardOwnerID)
    Unique = (AwardID+OwnerID+CeremonyID)

解决方案:2

    Ceremony
        -ID
        -NAME
    PK = (ID)
    Unique= (Name)

    Person
        -ID
        -NAME
    PK = (ID)
    Unique= (Name)

    Award
        -ID
        -NAME
    PK = (ID)
    Unique= (Name)

    AwardCeremony
        -AwardCeremonyID
        -AwardID    =fk TO Award.ID
        -CeremonyID =fk TO Ceremony.ID
        PK = (AwardCeremonyID)
        Unique = (AwardID+CeremonyID)


    AwardCeremonyRecipient 
        -AwardCeremonyID    =fk TO AwardCeremony.AwardCeremonyID
        -Recipient ID       =fk TO Person.ID
        PK = (AwardCeremonyID+Recipient ID)
于 2013-10-14T20:20:19.287 回答
0

一个人可以有一个或多个奖项

人有奖|| 1对多关系

person
- id (PK)
-award_id(PK,FK)
- name

award
- id (PK)
- name

//颁奖典礼可以有很多人

award_ceremony
-id (PK)
-person_id(FK)
-name
于 2013-10-10T09:39:34.707 回答