ruby on rails - Filter the loaded data using ROR -
i first preload activerecord one-to-many active records. possible filter out data followings without querying database again?
animal = @animals.all.includes({:cats}) animal.where([:cat_category=>"home_cat"]) ### 1
if located inside method, example
def load_something animal = @animals.all.load([:cats]) animal.where([:cat_category=>"home_cat"]) ### 1 end rails smart enough make 1 request db. if check in rails console, 1 line, type other, make 2 requests, in app, rails amke 1 db request
Comments
Post a Comment