# Polymorphic fields, PostgreSQL, and delete constraints

**URL:** <https://www.ruby-forum.com/t/polymorphic-fields-postgresql-and-delete-constraints/108340>\
**Category:** Rails\
**Created:** [July 2, 2007, 3:22pm UTC](https://www.ruby-forum.com/t/polymorphic-fields-postgresql-and-delete-constraints/108340 "2007-07-02T15:22:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pedz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/839c29/32.png) [@pedz](https://www.ruby-forum.com/u/pedz)\
**Post date:** [July 2, 2007, 3:22pm UTC](https://www.ruby-forum.com/t/polymorphic-fields-postgresql-and-delete-constraints/108340/1 "2007-07-02T15:22:51Z")

</div>

Say I have:

class Relationship \< ActiveRecord::Base  
belongs\_to :parent, :polymorphic =\> true  
end

and then several models like:

class Person \< ActiveRecord::Base  
has\_many :parents, :as =\> :parent, :class\_name =\> “Relationship”  
end

I do not want to allow a person to be deleted if they are still being  
used by a relationship. I think I could come up with a way to do this  
with Relationship.find(:first. Probably return just the id. If I get  
anything back, the validate method could fail. Something like that.

But I’m wondering if using “rules” inside of PostgreSQL would be  
significantly faster? I have never done rules so I’m a little timid.

Any advice?

Thank you,  
Perry
