On 11 Apr 2009, at 01:06, kojilab wrote:
>
> Hi,
>
> I have a weird behavior where an object association triggers a save
> when the parent record is not new.
>
According to "Unsaved objects and association" at
http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html
"Assigning an object to a has_one association automatically saves that
object and the object being replaced (if there is one),
in order to update their primary keys - except if the parent object
is unsaved (new_record? == true)."
Fred> My association is polymorphic like this
>
> class UserGuideline < ActiveRecord::Base
> has_one :recurring_task, :class_name =>
''UserRecurringTask'', :as
> => :taskable, :dependent => :destroy
> end
>
> class UserRecurringTask < ActiveRecord::Base
> belongs_to :taskable, :polymorphic => true
> end
>
> If do
> g=UserGuideline.find(id)
> g.recurring_task = UserRecurringTask.new
>
> it triggers the save and the validation
>
> Anyone had this issue?
>
> Thanks
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---