How to maintain the many-to-many association between ActiveRecord model and ActiveResource model in rails?

155 views Asked by At

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.

1

There are 1 answers

1
Ben On

In terms of using ActiveResource, what I imagine is that

  1. Create an RESTful API in A for sharing location.
  2. 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