[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Getting associations list

Alessandro [AkiRoss] Re

9/20/2007 9:37:00 AM

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

--
~Ale

1 Answer

Alessandro [AkiRoss] Re

9/20/2007 10:24:00 AM

0

Ok, i found reflections. Sorry for the disturb

--
~Ale