How to use 2 schema at a same time?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • littlemaster
    New Member
    • Apr 2010
    • 25

    How to use 2 schema at a same time?

    I want to use two schema in single rails application, for that how to specify the schema name in model. Tried with following, it was not working.
    set_table_name "schemaname.tab lename"

    schema names:

    1. addressbook
    2. schedule

    Need to fetch the details from addressboook schema and have to get some data from user and need to store it in a 'schedule' schema with all details.
  • improvcornartist
    Recognized Expert Contributor
    • May 2007
    • 303

    #2
    set_table_name "schemaname.tab lename" doesn't work because the application is connected to one default schema. It expects whatever you pass to set_table_name to be a table name within the model's schema.

    You should be able to get the application to work by setting up a second ActiveRecord connection for whichever is not the default (Base).

    Code:
    # This is the default connection
    ActiveRecord::Base.establish_connection(
    :adapter => ?mysql?,
    :host => ?localhost?,
    :username => ?user?,
    :password => ?pw?,
    :database => db_name
    )
    # This is the second connection
    ActiveRecord::Schedule.establish_connection(
    :adapter => ?mysql?,
    :host => ?localhost?,
    :username => ?user?,
    :password => ?pw?,
    :database => db_name
    )

    Comment

    • littlemaster
      New Member
      • Apr 2010
      • 25

      #3
      It was not working as per expected. I have used database.yml file with specifying 2 schemas.

      Comment

      Working...