Forum: Ruby on Rails ActiveRecord strange behavior

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.
588b8a8cef3c8231ff4cf6948d5e1991?d=identicon&s=25 Luciano Broussal (Guest)
on 2006-02-22 16:53
(Received via mailing list)
Hi all,

I have a has_many relation between Parent and Child

Parent  p
Child c

p.children << c  => create the relationship in the database (why not
need
p.save to see the child add?)

why when i modifiy a field in c.how_old i have to explicity call to
c.save if
i want to see the modification in database (p.save doesn't persist the
modification of chlild c)
because when i modify the child c and apply p.save it does nothing !!!

Other question Why p.children << c doesn't need to do p.save to see c in
database. (<< operator already done it !!)


Regards

Croco
Bf66e10c8fc4abefebde0425e7f6f15a?d=identicon&s=25 Norman Timmler (Guest)
on 2006-02-22 18:16
(Received via mailing list)
Am Mittwoch, den 22.02.2006, 16:51 +0100 schrieb Luciano Broussal:

> Other question Why p.children << c doesn't need to do p.save to see c
> in database. (<< operator already done it !!)

Because the foreign-key sits in the children table and therefor only
this one needs an update. A save on the parent won't have any affect.
--
Norman Timmler

http://blog.inlet-media.de
This topic is locked and can not be replied to.