Find all association methods

Hi all,

I want to get all association methods in one single model....

Any default method is provided by Active Record ???

i am using ruby 1.9.3 and rails 3.1.3

Please reply me ....

Thanks,

kingston.s

Hi all,

I want to get all association methods in one single model....

What do you mean "get" the methods?

Colin

User.reflect_on_all_associations.map{|a| [a.macro,a.name]}

etc.

Peter

Hi Peter,

Thanks for quick reply..

This is working fine.but it is return all the association and the corresponding model name....

like [:has_many, :site_users]

but i want association methods like site_user_ids and site_user_ids=

kingston.s

Hmmm, I don’t see them in that datastructure. I presume they are defined automatically, based on the name of the association, in this code starting at:

https://github.com/rails/rails/blob/master/activerecord/lib/active_record/associations/builder/collection_association.rb#L57

In general … I think it is better not to touch the _id fields manually and use other association methods (without _id) if possible. E.g. the ‘build’ or ‘delete’ functions on the has_many association.

HTH,

Peter