Skip to content

Support dependent destroy in association #31

Description

@draveness

Use SQL trigger to implement destroy dependent. ex:

CREATE TRIGGER article_comment_association_dependent_destroy
AFTER DELETE ON articles
FOR EACH ROW BEGIN
DELETE FROM comments WHERE private_id = (
    SELECT private_id FROM article_comment_associations
    WHERE article_id = OLD.private_id;
)
END;

Article and comment models are like this:

define :article do
    has_many :comments, :dependent => :destroy
end

define :comment do
    belongs_to :article
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions