rename
rel.rename(:a => :x, :b => :y, ...)rel.rename({ a: 'x', b: 'y' })Problem
Section titled “Problem”Rename one or several attributes.
Example: I want the product list, but pid should be called product_id instead.
Description
Section titled “Description”Creates a new relation identical with the input, except with any number of attributes renamed.
Requirements
Section titled “Requirements”The specified attributes must be part of the input relation’s heading.
Examples
Section titled “Examples”Consult the Overview page for the data model used in this example.
suppliers.rename(:sid => :supplier_id).to_a
=>[{:supplier_id=>"S1", :name=>"Smith", :status=>20, :city=>"London"}, {:supplier_id=>"S2", :name=>"Jones", :status=>10, :city=>"Paris"}, {:supplier_id=>"S3", :name=>"Blake", :status=>30, :city=>"Paris"}, {:supplier_id=>"S4", :name=>"Clark", :status=>20, :city=>"London"}, {:supplier_id=>"S5", :name=>"Adams", :status=>30, :city=>"Athens"}]Generated SQL
Section titled “Generated SQL”SELECT `t1`.`sid` AS 'supplier_id', `t1`.`name`, `t1`.`status`, `t1`.`city`FROM `suppliers` AS 't1'suppliers.rename({ sid: 'supplier_id' }).toArray()
// =>// [{ supplier_id: "S1", name: "Smith", status: 20, city: "London" },// { supplier_id: "S2", name: "Jones", status: 10, city: "Paris" },// { supplier_id: "S3", name: "Blake", status: 30, city: "Paris" },// { supplier_id: "S4", name: "Clark", status: 20, city: "London" },// { supplier_id: "S5", name: "Adams", status: 30, city: "Athens" }]