Getting associations list

A

Alessandro Re

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top