Forum: Ruby on Rails Handling database table dependencies

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
6f3f4fcb842db4b755cd8adc8bca67c6?d=identicon&s=25 ms (Guest)
on 2009-03-18 12:06
(Received via mailing list)

thanks for reading this post. How do you handle dependencies? A really
simple example: I've got a table called "entity" and another table,
let's say, "entity_type". The entity types can be changed, of course,
they also should be deletable, but only, if they are not used by some
entities! How can I ensure this in Rails or directly in the DBMS
(postgres)? Do I have to check it manually within a validate-method in
the model?

Thanks for any suggestions!

Cheers, ms
Ad97d898eefbb44ba50c07ee8554781b?d=identicon&s=25 Richard Mcintyre (mackstar)
on 2009-03-19 06:19
(Received via mailing list)
Are you talking about a polymorphic association??

You can set that up simply enough in the models after doing a wee
search on them,

May have some interesting insight into them, it would then be easy
enough to create a method from a before_destroy callback to check if
it is being used or not...


This topic is locked and can not be replied to.