Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Bribin's avatar

Help with Has Many Relationships Database Table

I have 2 Tables proposals & Proposal Attachments. each proposal has a docx file & Pdf File. let me know the below table design is correct

proposals

    ----------------------------------------------------
    | id | proposalNo | ProposalTitle | Status |
    ----------------------------------------------------
    | 1   |  PRO 123       | sample        | 0          |
    ----------------------------------------------------

proposal_attachments

    ---------------------------------------------------------------------------------------
    | id | proposal_id | version_ID |  Status  |    fileName           | filetype  | 
    --------------------------------------------------------------------------------------
    |  1  |        1               | 1                   |     1          |  Sample1.docx  |      doctype |
    ---------- -------------------------------------------------------------------------
    |  2 |         1               | 1                   |     1          |  Sample1.pdf     |       pdf          |
    ----------------------------------------------------------------------------------------
    |  3  |        1               | 2                   |     1          |  Sample1.docx  |     doctype   |
    ----------------------------------------------------------------------------------------
    |  4  |        1               | 2                   |     1       |  Sample1.pdf    |     pdf          |
    --------------------------------------------------------------------------------------

is this the correct design of Table or Not?

0 likes
5 replies
Yorki's avatar

Yes its correct one to many relationship. However you have inconsistency in your column namig, once you do snake case, once camel case, once id is uppercased, once lowercased.

1 like
Bribin's avatar
Bribin
OP
Best Answer
Level 1

@Yorki Let me know it the proper way of saving doc and pdf of the same version?

or

        | id | proposal_id | version_ID |  Status  |    filetitle    | fileNamedoc | fileNamePDF
    -----------------------------------------------------------------------------------------------------------
Yorki's avatar

@Bribin In my opinion first solution is better and more flexible in future development. Lets say you would like to add new file type. In first solution all you do is specify string for it while in second you end you up adding new column. More file types = more columns which is bad idea.

Bribin's avatar

my usage is on upload docx .. automatically docx convert into PDF file & store files. after in show blade. based on proposal ID and Version ID- PDf version. im using cloudconvert Api for Converting PDF,

HDS2019's avatar

Yes, your design is correct, it is 1-M Relationship

Please or to participate in this conversation.