The Hanami model is rom-based, so you can use the method Relation#joinwith the necessary ratio.
To do this, you need to call the method joinfor one relationship and set another relation as an attribute:
class PostRepository < Hanami::Repository
associations do
has_many :comments
end
def join_example(date_range)
posts
comments
posts
.join(comments)
.where(comments[:created_at].qualified => date_range)
.as(Post).to_a
end
end
And that’s all.
Some useful links:
source
share