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_scope :order => 'created_at DESC', :include => :author
end
With or without the :include
, the SQL is the same (i.e. it is only selecting from the posts table).
What is the way to do this?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With