Let's say I have two Post and Category models:
class Post < ActiveRecord::Base belongs_to :category end class Category < ActiveRecord::Base has_many :posts end
Is there a way that allows me to do something like
posts = Post.find(:all) p = Array.new p[1] = posts.with_category_id(1) p[2] = posts.with_category_id(2) p[3] = posts.with_category_id(3) ... or p = posts.split_by_category_ids(1,2,3) => [posts_with_category_id_1, posts_with_category_id_2, posts_with_category_id_3]
In other words, βsplitβ the collection of all messages into arrays with the selected category identifiers
source share