rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.08k stars 161 forks source link

Can't use timestamps plugin from inside a repo #467

Closed solnic closed 6 years ago

solnic commented 6 years ago

From @alexandru-calinoiu on April 23, 2017 15:36

My repo look like

    class Entries < IngestService::Repository[:entries]
      relations :ingest_steps
      commands :create, use: :timestamps
   end

I expect that calling Entries.new.create(args) will add timestamps to my entry, but that is not the case.

The Timestamp plugin get's applied at runtime when I call create, only then ClassInterface is extended adding timestamps method that can be used to configure the colmuns. Without calling timestamps the InstanceMethods will never be included and thus timestamps never added.

Unfortunately my understanding of the plugins is very limited, they look like being targeted mostly to commands, will love some pointers for the right direction.

Copied from original issue: rom-rb/rom-sql#189

solnic commented 6 years ago

From @alexandru-calinoiu on April 23, 2017 15:37

One easy way to solve it is for the timestamp_column to have default values, but is not complete as one won't be able to configure them from a repo.

solnic commented 6 years ago

Ah, right. I'm sorry I forgot we didn't make timestamps plugin work with repos yet. This will be addressed in rom 4.0 as we need to improve plugin architecture first.

solnic commented 6 years ago

In order to make this work, we need to enable passing options for command plugins here and then refactor timestamp plugin, so that Timestamp is a Module subclass, and accepts options. Then based on these options we can automatically configure a command. I would also say that this plugin should be moved to core, as it is not sql-specific.

GustavoCaso commented 6 years ago

@solnic I would love to help with this one

solnic commented 6 years ago

Done via https://github.com/rom-rb/rom/commit/962bb273931a7b224bfb0c4eb52e940f76af7e40