2015-06-20 89 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]}