views:

178

answers:

1

Are there any performance/other implications in having an object relates to itself? (self join)

Consider the following example:

PEOPLE (table name)
belongs_to :profile, :class_name => 'Person', :dependent => :destroy
id
login
password
first_name
last_name
profile_id

This question is party stemmed from another question posted at http://stackoverflow.com/questions/1032568/database-design-related

+1  A: 

You don't specify which database you are using, but AFAIK, not only will there not be any performance problems with self joins, there may be performance benefits over some alternative solutions.

Apart from that, IMHO it is easier to understand than say nested SQL statements, but that is entirely subjective.

See:

http://databases.about.com/od/sql/a/selfjoin.htm

CJM
It is not specific to any database (database agnostic). But the implementation is for a rubyonrails app. So all the SQL generation is taken care by rails internals itself. By declaring the relationships, I can see it works. Wanted to know if there are any problem at the time of delting these records as both records (person and profile) in somecases could be same.
satynos