查询输出中的字段太多

时间:2015-06-20 22:19:58

标签: ruby-on-rails ruby sqlite

我有一个查询,我只想输出三个变量

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}

1 个答案:

答案 0 :(得分:2)

select始终返回id属性,您可以在map中删除它:

Relationship.select('follower_id as source, followed_id as target, value').map{|x| [x.source, x.target, x.value]}