Rails Database-ActiveRecord Tricks

This explains how to manage database. In include the database switching in Rails ActiveRecord. To switch database:
  
  
  ActiveRecord::Base.connection.schema_search_path='your_schema'
  
To show the current database:
  
  
  ActiveRecord::Base.connection.current_database
  
To show the current schema:
  
  
 ActiveRecord::Base.connection.current_schema
  
Display all associated Models
  
  
  User.reflect_on_all_associations

  reflections = User.reflect_on_all_associations

  reflections.each do |reflection|
   puts ":#{reflection.macro} => :#{reflection.name}"
  end
  

No comments:

Post a Comment