On Thursday, July 12, 2012 6:48:58 AM UTC-7, Jamie Hodge wrote:
>
> Hi Jeremy,
>
> I have been using the touch plugin to update the timestamps on records 
> when many_to_many associations are added or removed (to support caching for 
> the web). 
>
> First of all, is this an anti pattern? 
>

Well, if you can do it in the database via a trigger, that may be a better 
way.
 

> If not, there is an annoying gotcha:
>
> The touch method takes a column argument and the after_add and 
> after_remove hooks send the associated record as an argument. Including 
> :touch as a callback results in no column being updated. Instead, one needs 
> to create a wrapper method that calls touch with no arguments.
>

That makes sense.  Seems like a simple enough work around.  You could 
redefine touch to call super with no argument as well.  That may be simpler 
if you don't need the flexibility of being able to specify a different 
column.

I'm surprised using :touch as a callback doesn't raise an Error, unless you 
have set strict_param_setting = false for your model.

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sequel-talk/-/Np_CUkWPhbYJ.
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