Forum: Ruby on Rails programmatic way to find associations? (ActiveRecord)

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.
F8d196408f5a602e0fed6096d41ed5f9?d=identicon&s=25 gm gm (gmoniey)
on 2009-04-10 22:37
Is there a programmatic way to find the different associations that an
particular model has?

For example, if I have the following:

class File < ActiveRecord::Base
  belongs_to :directory
  has_many :comments
end

is there a way to get the list of symbols/strings that this class has
associated under the has_many association?
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-04-10 22:49
(Received via mailing list)
On Apr 10, 9:37 pm, gm gm <rails-mailing-l...@andreas-s.net> wrote:
> Is there a programmatic way to find the different associations that an
> particular model has?
>
Take a look at YourClass.reflections and the various reflect_on_xxx
methods

Fred
F8d196408f5a602e0fed6096d41ed5f9?d=identicon&s=25 gm gm (gmoniey)
on 2009-04-11 06:26
Thanks....I could never find that on my own...
This topic is locked and can not be replied to.