I assume you are using the touch plugin, since Sequel::Model doesn't
On Saturday, October 6, 2012 7:04:34 PM UTC+2, Marc Cooper wrote:
> I add created_at and updated_at fields to all tables via before_create and
> before_update on Sequel::Model. Works great.
support automated setting of those fields by default.
There is not currently a way to do so automatically in Sequel.
> I now have a many_to_many relationship with its associated join table.
> Again this all works fine.
> However, in the case of the join table, the two *_at fields are not
> Is there a way to have these fields touched on creation and update?
Currently, the touch plugin doesn't appear to work correctly with
many_*_many associations, at least on some databases. I'm considering
changing the plugin so that it doesn't drop down the the dataset layer for
updating associations, which it currently does for performance reasons, but
which causes issues (see issue #566 on GitHub). Note that that still won't
do what you want, since it wouldn't update the join table.
Personally, I recommend using database defaults for created_at columns and
database triggers for updated_at columns, when possible, as they are more
reliable and have fewer issues once initially setup.
Assuming you can't use a database trigger, the best way to do what you want
currently is an after_save hook that updates the join table: