Today i would like to share about viewing associations of a particular model together in console.
How to get rails associations from console
1) User Model associate with UserDetail and Photo Model
class User < ActiveRecord::Base
has_one :user_detail
has_many :photos
end
2) Open your rails console
User.reflect_on_all_associations.map{ |reflection| ":#{reflection.macro} => :#{reflection.name}"}
=> [":has_one => :user_detail",":has_many => :photos"]
How to get rails associations from console
1) User Model associate with UserDetail and Photo Model
class User < ActiveRecord::Base
has_one :user_detail
has_many :photos
end
2) Open your rails console
User.reflect_on_all_associations.map{ |reflection| ":#{reflection.macro} => :#{reflection.name}"}
=> [":has_one => :user_detail",":has_many => :photos"]