# Defining has\_many without a foreign key

**URL:** <https://www.ruby-forum.com/t/defining-has-many-without-a-foreign-key/153655>\
**Category:** Rails\
**Created:** [November 19, 2008, 9:31pm UTC](https://www.ruby-forum.com/t/defining-has-many-without-a-foreign-key/153655 "2008-11-19T21:31:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![normelton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f1d935/32.png) [@normelton](https://www.ruby-forum.com/u/normelton)\
**Post date:** [November 19, 2008, 9:31pm UTC](https://www.ruby-forum.com/t/defining-has-many-without-a-foreign-key/153655/1 "2008-11-19T21:31:03Z")

</div>

Is it possible to have a has\_many relationship without a foreign key?  
I’d like to eager-load associations based on some arbitrary SQL. For  
instance, I would like to do something like:

:has\_many :neighbors, :class\_name =\> “Person”, :conditions =\>  
[“street\_id=?”, self.street\_id]

I believe this would work, but it would still look for a foreign key.  
I know I could do this with named\_scopes, or defining some method. But  
I’d like to eager-load all the neighbors at once.

Thoughts? Thanks!

Norman
