I have a rails app A, hosts most of the data, and have another app B uses some info in a table called location of A, and the location is many-to-many with users in B, for the decoupling reason I did not want to share DB between A and B, so I just want to use ActiveResource for B to get the model info from A, and keep the association in B, so the question is how to handle the association? Maybe just maintain a id relation table in B, and then how to sync the two DB.
Asked
Active
Viewed 140 times
0
-
I would suggest doing this through your database (or something that runs closely to your database like slony), and not through your code. If you build this yourself, it will get unmanageable very quickly. Some concerns if you do it yourself: Will you synchronize updates? What about transactions? What about consistency, when your two databases are out of sync? – Neal P Jan 03 '17 at 05:47
1 Answers
0
In terms of using ActiveResource, what I imagine is that
- Create an RESTful API in A for sharing location.
- Define the Location Model in B using ActiveResource
Then we can use location as a normal Model in B. Or we could create an API server isolated from both A and B. I'm not sure about the the association issue you mentioned above. Maybe I misunderstood the question?
class Location < ActiveResource::Base
self.site = "http://api.b.com:3000"
has_many :users, through: :location_users
end

Ben
- 1
-
The problem is: we should has a location_users table in B, the location_users contain the location_id and user_id, but what about if the location has been delete in A, we then should hit an error, by the way, the location_user has some business logic like keep user location special info. – Charles Chu Jan 04 '17 at 03:40