Forum: Ruby on Rails Polymorphic fields, PostgreSQL, and delete constraints

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.
Perry S. (Guest)
on 2007-07-02 17:22
Say I have:

class Relationship < ActiveRecord::Base
  belongs_to :parent, :polymorphic => true

and then several models like:

class Person < ActiveRecord::Base
  has_many :parents, :as => :parent, :class_name => "Relationship"

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,
This topic is locked and can not be replied to.