This project is archived and is in readonly mode.
has_many :dependent => :restrict
-
Steven Soroka
Patch attached
-
Marshall
+1 on the idea. However I think there's a bug if you have other associations with :dependent => :destroy on the same model. See http://lists.rubyonrails.org/pip... for a previous discussion of the problem.
-
Marshall
I should've posted a bit more information on the problem... if you have :dependent => :destroy on a different association that is defined before the :dependent => :restrict association, then the first association's before_destroy will fire before the restricted association raises the exception.
-
Steven Soroka
Hmm, good point, I'll have to fix that.
-
Xavier Shay
I want this
-
Xavier Shay
though it should return false rather than raise I don't quite understand Marshall's problem - all the callbacks happen in a transaction so who cares if the :destroy callbacks trigger first? (aside from maybe performance)
-
Steven Soroka
Maybe it's a problem because mysql in myisam mode doesn't support db transactions?
-
wildchild
Quite useful. Any status update?
-
Steven Soroka
I have some time, I'll take another look at this. I think you'd be fine to use the patch as long as you have transaction support in the database.
-
Ryan Bigg
- State changed from new to incomplete
- Importance changed from to
Please update this patch to apply to current Rails master and 2-3-stable.
-
Prem Sichanugrist (sikachu)
- Assigned user set to Prem Sichanugrist (sikachu)
I think this would be better included in 3.1.
However, do you think this feature should support non-transactional database engine too? If so, I have to find the way to make the relational checking to be the topmost callback.
-
François Beausoleil
Couldn't this simply add a validation check before anything else? Then validation will pick the problem, and before_destroy callbacks won't have a chance to fire. This should anyway be complemented with a constraint in the DB.
I created a duplicate ticket, even though Google didn't return anything useful: #6199 has_many :dependent => :deny
-
rails
- Tag changed from 2.2, activerecord, association, has_many to 22, activerecord, association, has_many
- State changed from incomplete to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails
- State changed from open to stale
