Forum: Ruby on Rails Way to iterate over each associtaion

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
385174ee0ad01f8e48e93319ef40abb7?d=identicon&s=25 David Clements (Guest)
on 2006-03-23 23:25
(Received via mailing list)
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
9d1f5d2d9de70bd9a934f557dc95a406?d=identicon&s=25 Daniel ----- (liquid)
on 2006-03-23 23:37
(Received via mailing list)
I'm sorry David,

I can't answer but I would like to know as well..
6dab365a82517fb694650a57ee88e4a4?d=identicon&s=25 joey__ (Guest)
on 2006-03-24 00:00
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 topic is locked and can not be replied to.