Person has_many: :blogs
has_many: :articles
Blog has_one: :person
Problem:
person.<blogs and articles>.<order by last_updated>.last
I know that I can have a scope so that all returned blogs are automagically ordered by last time, but is there a way to return all blogs and articles sorted by time? Essentially, I'm looking for the last updated child of a parent object.
您可以整理两个查询的结果,并对结果数组进行调用排序。
(person.blogs + person.articles).sort_by(&:last_updated).last
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.