我需要hashify ActiveRelation!例如 我有這樣的ARRails ActiveRelation哈希
arel = MyClass.page(options[:page]).per(options[:per])
是在這裏簡單的方式來創建哈希
練習1的MyTable的主鍵的鍵哈希:
[#<Object id: 44, name: "name44" >, #<Object id: 2, name: "name2" >, #<Object id: 110, name: "name110">]
=>
{44=>"name44", 2=>"name2",110=>"name110"}
練習2:
[#<Object id: 44, name: "name44" >, #<Object id: 2, name: "name2" >, #<Object id: 110, name: "name110">]
=>
{44=>{:id=>44, :name=>"name44", 2=>{:id=>2,:name=>"name2"},110=>{:id=>110,:name=>"name110"}}
能不能請你改一下你的問題? :-) – 2011-12-22 19:31:00