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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3f38541776a2513a20ea2f1c2d522cb3?d=identicon&s=25 Perry Smith (pedz)
on 2007-07-02 15:22
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
This topic is locked and can not be replied to.