On Oct 20, 12:12 am, David Lee <[email protected]> wrote:
> > Because of the way the internals work, this wouldn't be easy to do
> > cleanly.  Can you give me an example of an after_update hook you are
> > using that you would want to be run regardless?
>
> One simple example would be to save assocations:
>
>   class User
>     one_to_many :pictures
>
>     def pictures=(imgs)
>       @imgs = imgs
>     end
>
>     def after_save
>       save_pictures_with_user_id(id)
>     end
>   end
>
>   user = User.create(:name => 'Bob', :pictures => imgs) # works
>   user.update(:name => 'Bob', :pictures => other_imgs) # does not work
>   user.update(:name => 'Sally', :pictures => other_imgs) # works
>
>   User[123].update(:name => 'Bob', :pictures => imgs) # works if user
> name was not Bob
>   User[456].update(:name => 'Bob', :pictures => imgs) # does not work
> if user name was Bob

In that case, I'd do:

  def modified?
    super || @imgs
  end

Actually, maybe there should be a Model#modified! method that modified
considers, usable like:

 def pictures=(imgs)
   @imgs = imgs
   modified!
 end

If you call modified!, the record is considered modified until the
next time it is saved (so update and save_changes will attempt to save
the record).  Do you think that would make sense?

Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to