To address similar situations I've taken to defining an additional
method in the parent object which tries to save the parent and all the
children. Something along the lines of:
class Author
def save_with_associations
self.class.transaction do
result = true
self.stories.each { |s| result &= s.save }
result &= self.save
result || raise(RecordNotSaved)
end
rescue ActiveRecord::RecordNotSaved
false
end
end
This snippet is untested. It doesn't sound like you want to save every
story every time, but maybe this will lead to a better idea. :)
-John
On 10/2/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Okay, but unless I'm missing something, doing
>
> a.stories.find_by_title("some string").update_attributes(blah)
>
> or
>
> s = a.stories.find_by_title("some string")
> s.update_attributes(blah)
>
> doesn't just associate that Story record as something that
> needs to be saved when model object "a" is saved. It in
> fact saves it immediately as part of update_attributes(). I was
> originally looking for the former behavior. The main idea
> was to do all my modification on objects in memory, then
> a final "a.save". The idea is that I'm putting off all
> my validation until one point in time when everything gets
> validated. I was trying to avoid having validations firing
> at varying times.
>
> Perhaps it's not doable, or worth doing, but it did seem
> odd that this all works like a charm if you're dealing
> with *new* objects instead of objects reflecting records
> already in the database.
>
> Thanks again.
>
>
> -glenn
--
John Parker
[EMAIL PROTECTED]
_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby