I live in Brooklyn, NY with Anna and Hubble+Ollie. I perform music with French Miami, engineer software for Tumblr and co-created Views.fm.
You can ask me something.
ActiveRecord is pretty smart sometimes. Self-referential has_many relations are totally possible, and rails builds a pretty query to do it.
Check it:
class Nose < ActiveRecord::Base
has_many :similar_noses, :class => 'Nose', :foreign_key => 'nose_type', :primary_key => 'nose_type'
end
crooked_nose = Nose.find_by_name('Crooked')
crookeds = crooked_nose.similar_noses
# SQL: SELECT * FROM noses WHERE nose_type = 'crooked_kind_of_nose'
crookeds.collect{|nose| nose.name }
# => ['Armenian', 'Polish', 'Broken', 'Crooked']loading…