Topic: has_many association and session
I have parent ActiveRecord object and a set of child ActiveRecord objects. I use has_many/belongs_to association between them (parent has many children). When I store parent object in session all its children is stored in session too. This is unacceptable - I wanted it to store just parent and make SQL calls for each children retrieval.
Here are my classes:
class Parent < ActiveRecord::Base
class Child < ActiveRecord::Base
Code that I use to store parent in session:
p = Parent.find(1)
session[:parent] = p
c = p.children
After that I've got session with all children of 1st parent!