# Legacy database and habtm

**URL:** <https://www.ruby-forum.com/t/legacy-database-and-habtm/117543>\
**Category:** Rails\
**Created:** [October 17, 2007, 10:09pm UTC](https://www.ruby-forum.com/t/legacy-database-and-habtm/117543 "2007-10-17T22:09:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubylover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8c91f0/32.png) [@rubylover](https://www.ruby-forum.com/u/rubylover)\
**Post date:** [October 17, 2007, 10:09pm UTC](https://www.ruby-forum.com/t/legacy-database-and-habtm/117543/1 "2007-10-17T22:09:59Z")

</div>

Greetings,

I’m fighting with a poorly designed SQL Server database. The database  
is not normalized whatsoever, so I’m running into some brick walls  
trying to get Rails to be friendly with it.

I need to create a habtm relationship between a User table I created  
and a Depletion model I created. Depletion points to a view in the  
database called “Dep” that has no primary key. It has a varchar-based  
column called “VendorNumber” that I want to use to populate Depletion  
side of the relationship. In the end, the user should be able to  
view the records for many Depletion vendors.

Is there a way to manually populate the join table to store the user  
id and the string-based vendornumber and still use some of the  
niceties afforded by the habtm relationship?

Thanks.

---

<div class="post-metadata">

**Author:** ![rubylover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8c91f0/32.png) [@rubylover](https://www.ruby-forum.com/u/rubylover)\
**Post date:** [October 22, 2007, 4:55am UTC](https://www.ruby-forum.com/t/legacy-database-and-habtm/117543/2 "2007-10-22T04:55:07Z")

</div>

This is still an issue to me. Does anyone have any ideas or  
suggestions?

Thank!

- j
