Skip to content

Support dependent destroy in association #31

@draveness

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

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