【发布时间】:2019-03-08 01:50:44
【问题描述】:
data = [
{ name: :name, model: :Address, field_type: :string },
{ name: :country, model: :Address, field_type: :string },
{ name: :street , model: :Address, field_type: :string },
{ name: :city , model: :Address, field_type: :string },
{ name: :count , model: :Property, field_type: :integer },
{ name: :count2 , model: :Property, field_type: :integer } ,
{ name: :count3 , model: :Property, field_type: :integer } ,
{ name: :count3 , model: :Property, field_type: :integer }
]
我有一个哈希数组,我想查询哈希值。我想知道最有效和最推荐的解决方案。
例如,我可能需要找到所有 :integer 的哈希名称。或者我可能想查询所有模型的名称:地址。或者我可能需要将所有 field_types 查询为唯一的。
我可以直接查询哈希数组吗?如果是这样,如果没有,是否有更好的方法使用主动模型或其他方法?
【问题讨论】:
-
如果它是散列的散列,那么它缺少一些值或键。例如:
data = { 1: {name: :name, model: :Address, field_type: :string}} -
抱歉,我的意思是哈希数组,已修复
标签: ruby-on-rails ruby ruby-on-rails-5.2