Getting associations list

Hi there,
how can I retrieve a list of associations for a given Active Record?
I mean, having:

class Foo < ActiveRecord::Base
has_one :bar
has_one :baz
belongs_to :gosh
belongs_to :gulp
end

get lists of all has_one associations, one for belongs_to
associations, etc? (or a list with every association, if possible
distinguishing the kind of assoc.).

On documentation i found that has_one adds some methods (.bar, .bar=,
.build_bar etc) to Foo, but actually doing Foo.column_names or
foo.attribute_names doesn’t give me any of the above fields (if none
has been built, it seems).

I need to give user the ability to specify one of these associations,
but without hard-coding, so i need to retrieve such lists for each
ActiveRecord.

Thanks

Ok, i found reflections. Sorry for the disturb

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