I see in the rom-rails there is a way to do this, I am not on rails fortunately.
What would be the best way to have these fields and have them populated and the updated_at field populated on save? at the moment I am manually doing this in my models to_h method, and then using this to persist for example:
class User
…
def to_h
{
…
updated_at: Time.now,
created_at: @created_at || Time.now
}
end
end
Which is a bit clunky for me and I could not find any examples out there demonstrating a solution.
# auto_register: false
# frozen_string_literal: true
require 'rom-repository'
module StartupTemplate
class Repository < ROM::Repository::Root
include Deps[container: "persistence.rom"]
end
end
# frozen_string_literal: true
module StartupTemplate
module Repositories
class DoctorRepository < Repository[:doctors]
def create(doctor_attrs_hash)
changeset = doctors.changeset(:create, doctor_attrs_hash).map(:add_timestamps)
changeset.commit
end
end
end
end