我有一个查询,我只想输出三个变量
Relationship.select('follower_id as source, followed_id as target, value').map(&:attributes)
然而,我得到的结果包括我不想要的id变量。我该如何摆脱它?
{"source"=>1, "target"=>3, "value"=>1, "id"=>nil},
{"source"=>1, "target"=>4, "value"=>1, "id"=>nil},
{"source"=>1, "target"=>5, "value"=>1, "id"=>nil},
{"source"=>2, "target"=>3, "value"=>1, "id"=>nil}
答案 0 :(得分:2)
select
始终返回id
属性,您可以在map
中删除它:
Relationship.select('follower_id as source, followed_id as target, value').map{|x| [x.source, x.target, x.value]}