I have a rails(3) app(Master), which has the schema, models and database. Also I have one other rails(5) app(service) which doesn't have any models but I am using (master) app database.
service app configuration
common_db:
adapter: postgresql
database: 'blog'
username: 'username'
password: 'password'
host: 'localhost'
pool: '10'
application_record.rb
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
establish_connection
Rails.configuration.database_configuration["common_db"]
end
then I added one same model in service app then trying to get some values from master application
class post < ApplicationRecord
has_many :comments
scope :article_comments, lambda { |a| select("created_at").joins('INNER JOIN comments on post.id = comments.post_id').where('article_id = ?',
a) }
end
and if I call Post.article_comments here this joins and all is not working, absolutely this will not work as we don't have any association or any models in service app.
Basically my question is
1) can I reuse this master database model with service app?
2) If I can use this then can I use it with all associations Example: Blog.comments in service app .....
3) Also is there any other good approach to reuse this, also I saw some articles https://hiltmon.com/blog/2013/10/14/rails-tricks-sharing-the-model/, this will be a good thing to do all?