Has one assciation insert record question

Dear all

I have two model, Event and EventDetail

class Event < ActiveRecord::Base
set_table_name “ssc_event”
set_primary_key “event_id”
has_one :event_detail, :class_name => ‘EventDetail’, :foreign_key =>
‘event_id’
end

class EventDetail < ActiveRecord::Base
set_table_name ‘ssc_event_detail’
set_primary_key “event_id”
belongs_to :event, :class_name => ‘Event’, :foreign_key =>
‘event_id’
end

The schema in ssc_event.event_id is an identity column.
The schema in ssc_event_detail.event_id is an integer column

I use the following ruby code to insert a new record, but I think it is
not clever.

a = Event.new
a.cluster_code = “KWC”
a.hosp_code = “CMC”
a.save
b = EventDetail.new
b.id = a.id.to_i
b.detail = “This is detail”

Any one have a better solution? Please share.

Many thanks
Valentino

On Jun 11, 9:53 am, Valentino L. [email protected]
wrote:

I use the following ruby code to insert a new record, but I think it is
not clever.

a = Event.new
a.cluster_code = “KWC”
a.hosp_code = “CMC”
a.save
b = EventDetail.new
b.id = a.id.to_i
b.detail = “This is detail”

with associations you get a.build_event_detail for free. The
associations guide (

) has more details

Fred