I have also problem with setting timestamps. My repo looks like:
require_relative './repository_base'
class DocumentationRepository < ROM::Repository[:documentations]
include RepositoryBase
# ...
end
And repository base is:
module RepositoryBase
def self.included(base)
base.class_eval do
struct_namespace Entities
commands :create, update: :by_pk, delete: :by_pk
end
end
def create(attrs)
super root.changeset(:create, attrs).map(:add_timestamps)
end
def update(attrs)
super root.changeset(:update, attrs).map(:add_timestamps)
end
end
However create and update methods don’t seem to be reloaded. Still getting ROM::SQL::NotNullConstraintError
for timestamps.
Edit - quoting @flash_gordon:
@buszu that’s because the commands macro overrides your create/update methods in the target class. If you’re using changesets just do
def create(attrs); root.changeset(:create, attrs).map(:add_timestamps).commit
and don’t use commands for update it’s similar,
def update(id:, **attrs); root.by_pk(id).changeset(:update, attrs).extend(:touch).commit