# ActiveRecords - two fks

**URL:** <https://www.ruby-forum.com/t/activerecords-two-fks/89300>\
**Category:** Rails\
**Created:** [March 19, 2007, 11:43am UTC](https://www.ruby-forum.com/t/activerecords-two-fks/89300 "2007-03-19T11:43:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zirael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/91b2a8/32.png) [@Zirael](https://www.ruby-forum.com/u/Zirael)\
**Post date:** [March 19, 2007, 11:43am UTC](https://www.ruby-forum.com/t/activerecords-two-fks/89300/1 "2007-03-19T11:43:34Z")

</div>

Hi,

```
 I have two database tables
 Briefly:
   Projects
      -type
      -designer_id
      -check_designer_id
      - ...
   Designers
      -name
      -...

 I want to create two foreign keys in Projects table and both with
 the same Designer table.

 How should I deal with that problem, I want to use ActiveRecords.
 Is it possible?
```

---

<div class="post-metadata">

**Author:** ![Zirael](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/91b2a8/32.png) [@Zirael](https://www.ruby-forum.com/u/Zirael)\
**Post date:** [March 19, 2007, 6:34pm UTC](https://www.ruby-forum.com/t/activerecords-two-fks/89300/2 "2007-03-19T18:34:29Z")

</div>

Zirael wrote:

> Hi,
> 
> ```
> I have two database tables
> Briefly:
> Projects
> -type
> -designer_id
> -check_designer_id
> - ...
> Designers
> -name
> -...
> 
> I want to create two foreign keys in Projects table and both with
> the same Designer table.
> 
> How should I deal with that problem, I want to use ActiveRecords.
> Is it possible?
> 
> ```

Yes, Serving from memory (at work taking a break), look at belongs\_to  
:foreign\_key to specify alternate/extra foreign key relationships…

class Project \< ActiveRecord::Base  
belongs\_to :designer, :foreign\_key=\>“designer\_id”  
belongs\_to :designer, :foreign\_key=\>“some\_other\_foreign\_key\_id”  
end

class Designer \< ActiveRecordBase  
has\_many :projects, :foreign\_key=\>“designer\_id”  
has\_many :projects, :foreign\_key=\>“some\_other\_foreign\_key\_id”  
end

Designer.find(:first).some\_other\_foreign\_keys.each { etc… }

hope this helps

ilan
