Closed cdesch closed 3 years ago
Hi,
I didn't try with ActiveRecord::Relation object but have you tried flatten
method in ruby?
Example usage: https://stackoverflow.com/questions/35736060/ruby-array-flatten
If you still need to do this, your best bet is to use pluck and pluck the IDs. Model.in_range(min_range..max_range, origin: x).pluck(:id)
And union each array of IDs with | and then at the end perform a query to find all records with those IDs Model.where("ID in (?)", ids)
I am returning a series of ActiveRecord::Relations from the GeoKit-Rails method in_range. I want to combine each of these so they can returned as one array of objects in a controller action.
code:
The current code gives me an array of ActiveRecord::Relations like this :
How can I combine these? I know there is a ActiveRecord::Relation Merge method, but it would look very messy to have the first item retrieved then having subsequent items merged into it. Is there a way to do it functionally, like how I might do it with Elixir's Reduce Method.