A Ruby ORM for RethinkDB


Enabling Timestamps

Include the Timestamps in your model to enable the timestamping mechanism as follow:

class User
  include NoBrainer::Document
  include NoBrainer::Document::Timestamps

When including the Timestamps module, the following behavior is inserted in the model:

field :created_at, :type => Time
field :updated_at, :type => Time

before_create { self.created_at = }
before_save   { self.updated_at = }

Timestamps are not exactly implemented as described because database updates are skipped when no attributes changed during a save. The above behavior would have the effect of always changing the attributes since callbacks are always triggered even when no attributes changed. This means that the updated_at timestamp is only set when a database update query is performed.

You may use touch() on an instance to update the updated_at field.