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

<<TABLE systems>>

id<<PK>> ( NOT database generated)
installation_date
manufacturer
serial_number

<<TABLE lifters>>
id<<PK>><<FK>> ( 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 ==


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

Thanks

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedNov 24, '11 at 1:27p
activeNov 24, '11 at 1:27p
posts1
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Vogon Primo: 1 post

People

Translate

site design / logo © 2022 Grokbase