SynchronizedModels
Add a model into another model with an external database connection.
Installation
Add this line to your application's Gemfile:
gem 'synchronized_models'
And then execute:
$ bundle install
In the root directory:
$ rails generate synchronized_models_initializer
Usage
Set the values of the external database in the configuration file that was created in config/initializers/synchronized_models.rb by rails generate synchronized_models_initializer
command.
Example:
class Account < ActiveRecord::Base
sync_remote_model model_name: :account
end
# Then:
Account::RemoteAccount.last
Account::RemoteAccount.create name: "Some name"
Or:
class Account < ActiveRecord::Base
sync_remote_model model_name: :user
end
# Then:
Account::RemoteUser.last
Account::RemoteUser.create email: user@example.com, password: 123456
Or:
class Account < ActiveRecord::Base
sync_remote_model model_name: :user, table_name: :admins
end
# Then:
Account::RemoteUser.last
Account::RemoteUser.create email: user@example.com, password: 123456
Contributing
Bug report or pull request are welcome.
Make a pull request:
- Clone the repo
- Create your feature branch
- Commit your changes
- Push the branch
- Create new Pull-Request
Please write tests if necessary.
License
The gem is available as open source under the terms of the MIT License.