Way to iterate over each associtaion

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

I’m sorry David,

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

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__

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs