# Associations without foreign keys?

**URL:** <https://www.ruby-forum.com/t/associations-without-foreign-keys/129608>\
**Category:** Rails\
**Created:** [February 20, 2008, 1:38am UTC](https://www.ruby-forum.com/t/associations-without-foreign-keys/129608 "2008-02-20T01:38:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Confused\_Vorlon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6f9a4e/32.png) [@Confused\_Vorlon](https://www.ruby-forum.com/u/Confused_Vorlon)\
**Post date:** [February 20, 2008, 1:38am UTC](https://www.ruby-forum.com/t/associations-without-foreign-keys/129608/1 "2008-02-20T01:38:11Z")

</div>

Hi Folks,

I have a game where users get access to technologies. The technology  
records aren’t owned - so a normal foreign key doesn’t make sense.

I want to tell rails not to bother with xxx\_id, and just to use  
conditions I set.

I can use finder\_sql for a has\_many  
base.has\_many :superstructures,  
:class\_name =\> ‘Technology’,  
:finder\_sql =\> “select \* from technologies where  
category = ‘Superstructure’” do  
def allowed  
find :all, :conditions =\> ‘research\_required \<  
2’  
end  
end

but the ‘allowed’ addition doesn’t work

For a has\_one, finder\_sql doesn’t seem to be an allowed option.

What I’d like is :foreign\_key =\> nil, then I could put my logic  
in :conditions  
-but that doesn’t seem to work either - rails just guesses the default  
key.

Is there a way to do this without just defining class methods on  
Technology?

Thanks.
