2015-06-20 87 views
0

字段太多我有一个查询,我只希望输出三个变量在查询输出

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} 

回答

2

select总是返回id属性,你可以在map摆脱它:

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