Ruby: How to get array instead of DataMapper::Collection in query result

here is my code:

today_ids_from_db = Rating.all(:fields => 'my_id', :ts_d => Time.now)

today_ids_from_db.class == DataMapper::Collection

but I need to get simple ruby array with my_id values

how to achieve this?

Answers


Try this code

Rating.all(:ts_d => Time.now).map(&:my_id)

You can also try out this Activerecord beauty called pluck

Rating.where(:ts_d => Time.now).pluck(:my_id)

Need Your Help

Why is this basic json call not working?

ajax vb.net json model-view-controller

The following JSON call always hits the AJAX error handler, and I can't figure out why:

R loop dataframe and create a vector from each row

r loops

New to R. I am trying to create a vector from each row in a dataframe, and name the vector after the position in the dataframe. Sample data: