Woj*_*hKo 4 ruby hanami hanami-model
是否可以在子类中创建连接查询Hanami::Repository?
我发现这个 pull请求实现了这个功能,但我在当前的代码库中找不到它.
小智 12
基于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
Run Code Online (Sandbox Code Playgroud)
就这样.
一些有用的链接:
| 归档时间: |
|
| 查看次数: |
629 次 |
| 最近记录: |