Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dependent destroy in association #31

Open
draveness opened this issue Sep 16, 2016 · 0 comments
Open

Support dependent destroy in association #31

draveness opened this issue Sep 16, 2016 · 0 comments

Comments

@draveness
Copy link
Member

draveness commented Sep 16, 2016

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant