On Jun 30, 2011, at 8:04 AM, Chris Corbyn wrote: > I think it would be more obvious when reading your code if you just called > #sum_lines before calling #save, since it would't be clear why you were > calling #save otherwise. > > You *can* hook into other methods, like valid? and dirty?, but having > side-effects here is probably not desirable: > > before :dirty?, :sum_lines
Echoing Chris, but more emphatically: For the sake of your future sanity and that of all other people who may have to deal with your code, and furthermore, for the love of all that's holy, do not mutate Resources in a :dirty? hook. If that's not enough of an entreaty, please just do it for my sake. I can think of precious little reason to mutate a resource in a :valid? hook, either. If you want to change a value on your resource before saving, just override the property setter (def property_foo=(new_value); ... do something cool.... super(correct_value); end). DM is not ActiveRecord, and you should rarely, if ever, need to do callback-based value modification. But seriously, go ahead and hook :dirty? if you must, but think long and hard about other ways to mutate your Resources before you choose to go that route. -- Emmanuel PS - This isn't directed at you, Juan, I just needed to say that loud and clear for anyone else reading the list who might consider it a decent option. -- You received this message because you are subscribed to the Google Groups "DataMapper" 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/datamapper?hl=en.
