# Customizing belongs\_to method

**URL:** <https://discuss.rubyonrails.org/t/customizing-belongs-to-method/23181>\
**Category:** rubyonrails-talk\
**Created:** [January 14, 2008, 2:47pm UTC](https://discuss.rubyonrails.org/t/customizing-belongs-to-method/23181 "2008-01-14T14:47:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [January 14, 2008, 2:47pm UTC](https://discuss.rubyonrails.org/t/customizing-belongs-to-method/23181/1 "2008-01-14T14:47:50Z")

</div>

Hi you all, I'm working with a legacy database that has: User: - id: primary key. - dirip: IP address. Bugs: ... -dirip: IP address (foreign key referring to User) A user can have generated many bugs, and a bug belongs to one user. However, as you can see, Bugs.dirip refers to User.dirip, not User.id (cause dirip is also unique, and the db creators thought this would be right).

So, in the belongs\_to declaration in Bugs, I can change the foreign\_key namebut... how can I say that this foreign key is not referring to User.id in the belongs\_to declaration??? If I can't change that, I have to override the user.bugs method and bug.user method, implementing mine, am I right?

Thanks.

---

<div class="post-metadata">

**Author:** ![Mark\_Wilden](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@Mark\_Wilden](https://discuss.rubyonrails.org/u/Mark_Wilden)\
**Post date:** [January 14, 2008, 8:03pm UTC](https://discuss.rubyonrails.org/t/customizing-belongs-to-method/23181/2 "2008-01-14T20:03:29Z")

</div>

One way might be to declare dirip as the primary key for User. I'd hate to have to do that (use external data for a key), but it's "a way."

///ark
