我想重命名列,一旦它們出來的數據庫查詢,所以我可以讓他們進入一個d3.js圖形正確的格式。這要求這些字段被命名爲源,目標,值。如何重命名字段進入json散列
def self.including_relationships
User.select(:follower_id,:followed_id,:value)
#How do I rename the fields from the line above to the fields below
obj['links'] << a.slice('source', 'target', 'value')
end
end
這是如何根據問題重新命名字段源,目標,值? –
User.select('follower_id as source,followed_id as target,value')。map(&:attributes)將執行這些操作。 –