Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a foreign key constraint using Yesod/Persistent?

Is there a way to create a foreign key constraint using Persistent's schema syntax with the Postgres backend? Or do I need to do this manually with SQL? Specifically, an ON DELETE CASCADE relationship such that when a HackDay is deleted, all of its child Projects are deleted:

HackDay
    title Text
    created UTCTime default=now()
    votingClosed Bool default=false
    deriving Show
Project
    hackday HackDayId
    title Text
    creators Text
    votes Int default=0
    created UTCTime default=now()
    deriving Show
like image 653
MaxGabriel Avatar asked Feb 06 '26 10:02

MaxGabriel


1 Answers

Persistent does not currently have any built-in support for triggers, though it's something we've been wanting to add (simply lacking manpower). For now, you'll have to add the trigger manually.

like image 107
Michael Snoyman Avatar answered Feb 09 '26 00:02

Michael Snoyman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!