开发者

Adding and removing referential integrity constraints - automatically

开发者 https://www.devze.com 2023-03-15 20:00 出处:网络
Is there a Rails gem, plugin or other means to automatically add开发者_如何学运维 or remove ALL RI constraints from your DB and schema?Or ALL of them on a per table basis?Something like:

Is there a Rails gem, plugin or other means to automatically add开发者_如何学运维 or remove ALL RI constraints from your DB and schema? Or ALL of them on a per table basis? Something like:

remove_all_foreign_key_constraints('comments')


No gems/plugins I'm aware of.

This is tricky though because rails (and most adapters) assume the referential integrity is maintained through your application's association.

If that's the case (associations ARE maintained in models), then you could write a little script that would construct the required SQL statements based on the model's association.

Association reflection might help:

http://api.rubyonrails.org/classes/ActiveRecord/Reflection/ClassMethods.html#method-i-reflect_on_all_associations

0

精彩评论

暂无评论...
验证码 换一张
取 消