# Integrate legacy tables

**URL:** <https://www.ruby-forum.com/t/integrate-legacy-tables/116930>\
**Category:** Rails\
**Created:** [October 11, 2007, 11:23am UTC](https://www.ruby-forum.com/t/integrate-legacy-tables/116930 "2007-10-11T11:23:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![inriz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/50afbb/32.png) [@inriz](https://www.ruby-forum.com/u/inriz)\
**Post date:** [October 11, 2007, 11:23am UTC](https://www.ruby-forum.com/t/integrate-legacy-tables/116930/1 "2007-10-11T11:23:03Z")

</div>

hello list,

weve got some tables of a earlier project, which have to integrate  
into rails.  
im now testing two tables.

RailsModelName | DatabaseTableName | primary\_key | foreign\_key

Advertiser INSERENT INSNR  
PrivProperty OBJPRIV RECCOU MAKNR

so, i wrapped these settings in my model see below

class Advertiser \< ActiveRecord::Base  
self.table\_name = “INSERENT”  
self.primary\_key = “INSNR”

has\_many :priv\_properties,  
:class\_name =\> “PrivProperty”,  
:foreign\_key =\> “MAKNR”  
end

class PrivProperty \< ActiveRecord::Base  
self.table\_name = “OBJPRIV”  
self.primary\_key = “RECCOU”

belongs\_to :advertisers,  
:class\_name =\> “Advertiser”,  
:foreign\_key =\> “MAKNR”  
end

so, to test the current construct, i started ruby script/console  
ins = Advertiser.find(12345) #works well but  
ins.priv\_properties # doesnt work -\> i got a nil object

the same with  
prop = PrivPropery.find(5678)  
prop.advertisers #-\> nil object

so, the development.log shows me the generated sql

ins.priv\_properties  
produces  
SELECT \* FROM OBJPRIV WHERE (OBJPRIV.MAKNR = NULL) # why NULL instead  
of the id?

prop.advertisers  
doesnt generate a sql, instead, it get nil

so why this relation doesnt work? are the names of has\_many and  
belongs\_to wrong?

thanks for help

best regards
