How to add `:include` to default_scope?

前端 未结 1 563
臣服心动
臣服心动 2021-02-07 06:11

Searching the \'net, I found that I should use :include, but that does not seem to change the SQL query that is generated:

def Post #model
  default         


        
1条回答
  •  执笔经年
    2021-02-07 06:29

    What if you do

    default_scope { includes(:author).order('created_at ASC') }
    

    This is the way that it’s documented in the Rails API for default_scope & scope, rather than the hash parameter method you're using.

    0 讨论(0)
提交回复
热议问题