On Friday, 11 April 2014 07:13:25 UTC-4, Ruby-Forum.com User wrote:
@Bs<<B.where(a_id: a, is_visible: true)
end
If you have “massive amounts” of B records, the DB server won’t be the
bottleneck - instantiating all those objects will be. Doing more SQL
queries is usually the opposite of optimization.
I’d also recommend you check out the associations guide on guides.rubyonrails.org. It’s possible to do things like:
class Blog < ActiveRecord::Base
has_many :visible_posts, → { where(is_visible: true) }, class_name:
‘Post’
end
class Post < ActiveRecord::Base
belongs_to :blog
end