
dm-constraints 0.9.10 breaks on auto_migrate! if a has association is missing
Reported by Greg Campbell | January 20th, 2009 @ 06:59 PM
If any belongs_to() association exists without a corresponding has() association on the other end, dm-constraints will raise an exception during auto_migrate! when attempting to retrieve the delete_constraint for the non-existent association. See attached script for an easy way to reproduce the issue.
Comments and changes to this ticket
-
Marcin Kulik January 21st, 2009 @ 04:35 AM
I can confirm this, I have the same problem after upgrading to dm 0.9.10.
-
Dan Kubb (dkubb) January 21st, 2009 @ 01:30 PM
- Assigned user set to Balint Erdi
-
Greg Campbell January 21st, 2009 @ 11:21 PM
I have a fix for the exception, but I'm curious what people think should be the default behavior in this case. Should the constraint be skipped, or should it be set to "NO ACTION"?
-
Dan Kubb (dkubb) January 21st, 2009 @ 11:41 PM
- State changed from unconfirmed to confirmed
I think it should be set to NO ACTION. As I mentioned on IRC, we should be designing things as constrained/strict as possible up-front, and only loosen them if we discover any of our assumptions to be incorrect. It is much easier to loosen a constraint later on than to tighten something.
-
Greg Campbell January 22nd, 2009 @ 11:05 AM
One problem with NO ACTION is that this sort of relationship won't be caught by the Ruby constraint-checking code, so that setting causes an attempted delete to either raise a database-level error (in the case of a supported adapter like Postgres or MySQL) or succeed (in the case of SQLite, etc.). Given that, I'm leaning back toward skipping the constraint to provide more consistent behavior across adapters.
-
Dirkjan Bussink January 22nd, 2009 @ 04:00 PM
I agree with Dan here, we should be as strict as possible. SQLite doesn't easily give you all the integrity options you want, so that it's not available there isn't really an argument imho.
-
Balint Erdi January 24th, 2009 @ 04:05 PM
I also think we should assume the developer's intention was not to allow the referred parent record to be deleted. So I opt for the "NO ACTION" constraint.
Greg, if you agree, could you let me know the status of your fix? Thank you.
-
Greg Campbell January 25th, 2009 @ 12:17 AM
Done, see http://github.com/gcampbell/dm-m... for the commit. I'll send a pull request in a moment.
-
Balint Erdi January 27th, 2009 @ 04:16 PM
- State changed from confirmed to accepted
-
Dan Kubb (dkubb) January 28th, 2009 @ 03:35 PM
- State changed from accepted to resolved
This is resolved with the following commit:
http://github.com/datamapper/dm-...
Please note that commit messages can be annotated so that the Lighthouse ticket is automatically resolved, eg:
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »