[Q] Active Ducking


#1

Hello,

I work with a legacy schema, thanks to Rails it’s not too difficult
out of the ID’s and plurals rules.

Got two tables (senders and receivers), they are identical in
structure like, just fieldnames are differents

SENDID number
SENDNAME varchar
SENDADDR varchar
…/snip

RECVID number
SENDNAME varchar
SENDADDR varchar
…/snip

I try to create a receiver from a sender :

s=Sender.find(42)
r=Receiver.new

r=<Attributes_from_S>
r.save!

Any magic code ?

Thanks for help.


#2

Mathieu C. wrote:

SENDADDR varchar
…/snip

I try to create a receiver from a sender :

s=Sender.find(42)
r=Receiver.new

r=<Attributes_from_S>
r.save!

If the attribute(field) names are the same (other than the ‘id’ field)
then you can assign one objects attributes from the other:

r.attributes = s.attributes

If they are different then you’d need to manage those differences
explicitly.


Lee


#3

Lee,

If the attribute(field) names are the same (other than the ‘id’ field)
then you can assign one objects attributes from the other:

In fact, I just wronk typed my tables. Fields names are different, and
I’ve used an easy but dirty fieldX to fieldY assignment.

Thanks for help.