Skip to content

Foreign Key Cascade Actions on "plain" foreign keys #1118

@parsonsmatt

Description

@parsonsmatt

Currently, the OnCascade functionality only works on explicit foreign keys.

User
  name String
  Primary name

Post
  user UserId
  Foreign User OnDeleteCascade fkuser user

We should also be able to write:

User
  name String
  Primary name

Post
  user UserId OnDeleteCascade

Problem surfaced in #1113

To implement this, we'll need to start with takeCols to parse the OnDeleteand OnUpdate behavior into the column type. However, we don't currently track whether or not this field is a reference yet, so we'll need to figure some other way to propagate the cascade behavior.

  • How should we handle cascade behavior on non-foreign key fields? ie:
    User
        name String OnDeleteCascade
    
    Easiest thing to do is ignore it silently. But throwing an error may work as well.
  • We will probably need to update FieldDef to accept the cascade behavior separately from the reference. Then, in fixForeignkeys, we'll copy that into the new reference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions