I have a topic that has many sources (sources belongs to topic). Each source has a published_date
field. What I want is to query the topic.sources
and group them into arrays of objects based published_date.
One way to do this call the topic.sources
, then sort them by published_date
. Lastly create new array for each date and shove it into the array accordingly.
topic.sources objects (array):
[#<Source id: 12, topic_id: 2, published_date: "2014-11-13">,
#<Source id: 9, topic_id: 2, published_date: "2014-10-21">
#<Source id: 8, topic_id: 2, published_date: "2014-10-21">]
This should look like this array of arrays:
[[#<Source id: 9, topic_id: 2, published_date: "2014-10-21">
#<Source id: 8, topic_id: 2, published_date: "2014-10-21">],
[#<Source id: 12, topic_id: 2, published_date: "2014-11-13">]]