# Joining tables where foreign key is not the \[singular\_of\_oth

**URL:** <https://www.ruby-forum.com/t/joining-tables-where-foreign-key-is-not-the-singular-of-oth/114170>\
**Category:** Rails\
**Created:** [September 9, 2007, 2:57am UTC](https://www.ruby-forum.com/t/joining-tables-where-foreign-key-is-not-the-singular-of-oth/114170 "2007-09-09T02:57:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@thomas](https://www.ruby-forum.com/u/thomas)\
**Post date:** [September 9, 2007, 2:57am UTC](https://www.ruby-forum.com/t/joining-tables-where-foreign-key-is-not-the-singular-of-oth/114170/1 "2007-09-09T02:57:15Z")

</div>

I am rather new to RoR and am having the following issue. I have read  
some conflicting posts so I wanted to see what people have to say for  
my particular example.

Here is what I have.

class Expense \< ActiveRecord::Base  
class Person \< ActiveRecord::Base

A person has the following fields (in the people table).

:fname, :string  
:lname, :string  
:email, :string

An expense has the following fields (in the expenses table).

:purchaser\_id, :integer  
:amount, :decimal  
:description, :string  
:event\_id, :integer

A person is the purchaser of an expense, but I don’t want to use  
person\_id as the field name in the expense model.

How do I create a has\_many and belongs\_to relationship. Clearly, a  
person will have many expenses (as a purchaser) and an expense will  
belong to a purchaser (or person).

Any help would be greatly appreciated.

Thanks,

Thomas

---

<div class="post-metadata">

**Author:** ![thomas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e36b37/32.png) [@thomas](https://www.ruby-forum.com/u/thomas)\
**Post date:** [September 9, 2007, 4:29am UTC](https://www.ruby-forum.com/t/joining-tables-where-foreign-key-is-not-the-singular-of-oth/114170/2 "2007-09-09T04:29:21Z")

</div>

On Sep 8, 2007, at 8:56 PM, Thomas wrote:

> How do I create a has\_many and belongs\_to relationship. Clearly, a  
> person will have many expenses (as a purchaser) and an expense will  
> belong to a purchaser (or person).

Look at the :foreign\_key and :class\_name options for the associations.

-faisal
