These are chat archives for dry-rb/chat

1st
Sep 2017
Chris Richards
@cmrichards
Sep 01 2017 09:24
The more I use dry-struct the more I want to use it for all the types in my application, and the more it seems like ActiveRecord doesn't play a part in that. I just need a tool to automatically map my database rows to these new types. Is this a normal reaction?
Andy Holland
@AMHOL
Sep 01 2017 09:43
@cmrichards you should check out rom schemas
It's a pretty awesome feature
Chris Richards
@cmrichards
Sep 01 2017 09:51
I spend most of my time working with large queries (10+ joins) and figuring out the best way of putting this data in classes. I'm not sure if ROM can, or is supposed to, help me with this. The "composing relations" feature of ROM looks like it might deal with that, but the examples given here are very simple so im not sure: http://rom-rb.org/3.0/learn/repositories/composing-relations/
Nikita Shilnikov
@flash-gordon
Sep 01 2017 09:53
  def fetch_for_rendering(invoice_id)
    invoices.
      by_pk(invoice_id).
      combine(
        bill: {
          tenant: [:order, :owner],
          items: { subscription: { plan: :type } }
        }
      ).
      one!
  end
@cmrichards ^this is rom 4.0.beta, the query hits nine tables
Chris Richards
@cmrichards
Sep 01 2017 09:55
Is it just one query or many?
Nikita Shilnikov
@flash-gordon
Sep 01 2017 09:56
9 relations -> 9 queries, it turned out joins are often slower than in-memory combination
keep in mind, there is no N+1 query problem in ROM
Chris Richards
@cmrichards
Sep 01 2017 09:57
For a lot of the stuff I do, doing the query in anything but SQL wouldn't work well
I've tried it before using Rails's join helpers (include, joins, etc..) and it was a whole world of pain
Nikita Shilnikov
@flash-gordon
Sep 01 2017 10:04
rom-sql has a powerful DSL for queries, including joins
and it'll become more powerful over time
Andy Holland
@AMHOL
Sep 01 2017 15:13
@cmrichards I'd be interesting in hearing more about this, and I'm sure Nikita would too (he's the most knowledgeable person I've ever met when it comes to SQL, or Ruby in general for that mater :))
Nikita Shilnikov
@flash-gordon
Sep 01 2017 21:52
when you write in pl/sql for seven years this is inevitable...
Tim Riley
@timriley
Sep 01 2017 22:51
I can't wait for the film adaptation of this superhero origin story.