Hello. I have a Threads
relation that has_many :messages
. When fetching thread list in the repository, I use select_append
to add message_count
value to the result. Something like this:
def with_count
left_join(messages).select_append {
[integer.count(messages[:thread_id]).as(:message_count)]
}
end
This works fine when I really use the repository. But in cases when I want to provide just structs of threads to some code, and when I try to use rom-factory
, I cannot set the message_count
there, because it only lets me set the attributes from the schema. It kind of makes sense, but does not let me achieve what I want.
I end up abusing Ruby like this:
thread = Factory.structs[:thread]
def thread.message_count = 1
Obviously it does not feel right. So I’ve been wondering:
- Is
rom-factory
missing functionality to do that? - Am I doing something completely against the philosophy of ROM?
- Or maybe my “workaround” is not really a workaround, but intended way?