[英]Join query in Hanami-model
基於rom的Hanami模型,這就是為什么你可以使用Relation#join
方法和一個必要的關系。
為此,您需要為一個關系調用join
方法並將其他關系設置為屬性:
class PostRepository < Hanami::Repository
associations do
has_many :comments
end
# ...
def join_example(date_range)
posts # => posts relation
comments # => comments relation
posts
.join(comments) # set relation object here
.where(comments[:created_at].qualified => date_range)
.as(Post).to_a
end
end
就這樣。
一些有用的鏈接:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.