Forum: Ruby on Rails [Q] Active Ducking

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F16def8015a7562a285c65a14be48540?d=identicon&s=25 Mathieu Chappuis (Guest)
on 2006-02-27 15:12
(Received via mailing list)
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.
C9806138c2b665621a723f0c88aff221?d=identicon&s=25 Lee O'Mara (Guest)
on 2006-02-27 15:21
(Received via mailing list)
Mathieu Chappuis 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
F16def8015a7562a285c65a14be48540?d=identicon&s=25 Mathieu Chappuis (Guest)
on 2006-02-28 14:17
(Received via mailing list)
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.
This topic is locked and can not be replied to.