1
有一种方法来delete_if数据:有没有办法收集?
Article.all.delete_if { |a| a.type != "Swimming"}
我在想,如果有一个类似的方法来“收集如果”约会?
有一种方法来delete_if数据:有没有办法收集?
Article.all.delete_if { |a| a.type != "Swimming"}
我在想,如果有一个类似的方法来“收集如果”约会?
你看过Array#collect
和Array#select
方法吗?
像这样工作的:
matching_articles = magazines.collect { |m| m.articles.where("type != 'Swimming'") }.flatten
collect_if =选择 – tokland
谢谢!这解决了它。 –