Reputation: 4516
I have a select statement that returns a field in a table.
records = Product.select("DISTINCT #{iFieldName}").where("id in (0, #{iInClaws})" )
I want to convert the data in the database to an array to be used later.. say as another inClaws.
records.each{|record| fieldArray << record.?????}
I have two questions.
def self.getFieldArray(iFieldName, iIDsInClaws, iIdFieldName = 'id')
records = self.select("DISTINCT #{iFieldName}").where("#{iIdFieldName} in (#{iIDsInClaws})" )
return records.map{|record| record.send(iFieldName)};
end
Upvotes: 0
Views: 137
Reputation: 16730
fieldArray = records.map(&:iFieldName)
Or
res = records.map{|r| r.send(iFieldName)}
Upvotes: 2