ruby - Using two or more databases in rails project -


I am using external user database for various projects.

Now I have got a school model in my project, which many users and users have many schools.

  class user & lt; ActiveRecord :: Base Installation_connection "# {RAILS_ENV} _tunnel" has_many: membership has_many: schools, via => : End of membership class school & lt; ActiveRecord :: Base has has_many: membership has_many: users ,: through = & gt; : Subscription to the end membership of the subscription & lt; ActiveRecord :: Base is_to: User is_to: school end  

So now I have a problem:

  • I can not call school. The table is in my project db, neither is external user in db), but i can call the user
  • I can not update like this: current_user.school.find (params [: id] ). Update_attributes (params [: school]), because it only opens the connection for reading in this way.

I understand how I can stop this problem, that is,

school. Users can call me like this:

  class school & lt; ActiveRecord :: Base is has_many: Subscription # has_many: users ,: through = & gt; : Membership def user user: where ("users.id in (?)", Self.connections.map (& amp; user_id)) and end  

but this hack is not enough Because now I have to go to school.users & lt; & Lt; User.find (203) , or school.users.find (params [: user_id]) and other features, which gives me many relationships.

Question is to work with two databases that are linked to each other by the support of the full facility.

I do not think this is a way of doing this in the rail with fully convenience - I thinks that you are trying to better use the remote db table in your output db.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -