Legacy MTI schema

Hi all,
In a legacy ‘immutable’ schema I have MTI inheritance setting:

<

>

id<> ( NOT database generated)
installation_date
manufacturer
serial_number

<

>
id<><> ( NOT database generated )
max_weight
drive

In my model I have implemented the semantic of inheritance between
System and Lifter in this way:

class System < ActiveRecord::Base

has_one :lifter
:foreign_key=>:id,
:dependent=>:destroy,
:autosave=>:true

delegate :drive, :drive=, :max_weight,:max_weight=,:to=>:lifter

trick for polymorphic query

end

class Lifter

belongs_to :system,
:foreign_key=>:id,
:dependent=>:destroy,
:autosave=>:true

delegate :manufacturer,
:manufacturer=,
:serial_number,
:serial_number=,
:installation_date,
:installation_date, :to=>:system

alias system_without_build system

def system

  system_without_build || build_system

end

end

In the client code :

lifter = Lifter.new
lifter.id=1327
lifter.installation_date= Date.parse(“7/8/2010”)
lifter.manufacturer=“FooLift”
lifter.serial_number=“1324AA”
lifter.drive=“Automatic”
lifter.max_weight=1200

lifter.save!

performs this wrong (in id) INSERTS:

INSERT INTO systems
(installation_date, manufacturer, serial_number)
VALUES (?, ?, ?)
[
[“installation_date”, Sun, 07 Aug 2010],
[“manufacturer”, “FooLift”],
[“serial_number”, “1324AA”]
]

INSERT INTO lifters
(drive, id, max_weight)
VALUES (?, ?, ?)
[
[“drive”, “Automatic”], [“id”, 0], [“max_weight”, 1200]
]

seems to loose the pre-assigned id setting (id=1327) and attempts to
fetch a database generated id. In other words after saving, lifter.id ==
0

I didn’t understand why, can someone help me please?

Thanks

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