【发布时间】:2018-02-12 09:39:08
【问题描述】:
我有一个活动记录 one -> many 关联,我需要 get all child rows 从特定行开始
类似
parent.children.startwith(some_child_row_id)
有单行吗?
编辑: 更清晰
假设我们有一个数组
a = ["a","b" ,"cg", "d","e"]
我希望"cg" 成为第一个元素。
我会做类似的事情
element = a.delete("cg") // array will be ["a","b","d","e"]
a.unshift(element) // array will now become ["cg","a","b","d","e"]
看!一个元素被移动到索引 0。
在 ActiveRecord 行的情况下我想要相同的,最好是 One-liner。
【问题讨论】:
标签: ruby ruby-on-rails-5 rails-activerecord