Integrate legacy tables

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs