Way to iterate over each associtaion


#1

Is there a way with ActiveRecord to get ahold of a collection containing
each association? I want to write a rake task that will dump a model
and
all its related models to yaml.

Thanks,
Dave


#2

I’m sorry David,

I can’t answer but I would like to know as well…


#3

Daniel ----- wrote:

I’m sorry David,

I can’t answer but I would like to know as well…

[Model.instance_methods -
ActiveRecord::Base.instance_methods].flatten.delete_if{|x|x=~/create_|remove_|destroy|build_|add_|set_|validate_|_count|=|[?]/}.map{|x|m=Model.find_first.send(x.to_sym);m
if m.class.superclass == ActiveRecord::Base||if
m.respond_to?(:first);m.first.class.superclass ==
ActiveRecord::Base;end}.compact.flatten

Nasty. I don’t know if there is a real way to do it.

joey__