Railsters:
I suspect the answer is “because they invented it before inventing eager
loading”.
The first minor issue with to_xml’s refusal to read my mind is it’s not
DRY
(like my mind!):
Model.all(:include =>{ :this => :that }).
to_xml(:include =>{ :this => :that })
With eager loading, every Model instance has its internal @this member
populated, and each This has its @that populated. So, instead of
repeating the
:include argument, to_xml could just find every populated @this and
@that
instance variable, and recursively call to_xml on it.
Do I misunderstand to_xml here? Or is it indeed refusing to read my
mind?
Another, more minor issue: to_xml( :except =>[ :secret, :password ] )
Is there, instead, a :pass argument, to positively declare what we do
want?
Negatively declaring the complete list of variables we don’t want
(being most
of them) is not just a waste of time, it’s fragile if we migrate more
secret
fields into our model!
Please advise if I need to RFTM, grab a plugin, or else just live with
to_xml’s
disturbing refusal to read my mind!
–
Phlip