# Polymorphic FK mapped to field other than ID

**URL:** <https://www.ruby-forum.com/t/polymorphic-fk-mapped-to-field-other-than-id/107959>\
**Category:** Rails\
**Created:** [June 27, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/polymorphic-fk-mapped-to-field-other-than-id/107959 "2007-06-27T20:51:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3bc359/32.png) [@jon](https://www.ruby-forum.com/u/jon)\
**Post date:** [June 27, 2007, 8:51pm UTC](https://www.ruby-forum.com/t/polymorphic-fk-mapped-to-field-other-than-id/107959/1 "2007-06-27T20:51:44Z")

</div>

Here’s the scenario:

I have a table that looks something like:

## containers

id  
name  
external\_id  
created\_ts

and another for tracking like:

## trackings

id  
created\_ts  
event  
trackable\_id  
trackable\_type

My containers table (along with a few others) has a polymorphic  
relationship to trackings. Normally, trackings would map to  
containers by the container’s ‘id’, but I want to see if I can have it  
reference containers by the external\_id, which comes from an external  
application after the record is created and will be unique.

Is this possible?

Thanks in advance for any info.

Jon
