0

I have 2 models with same name but in different mongo db's. I want to access these 2 models in one rails application. How can I do that?

I have referred to this question but I am not sure how it fetches data if it has same model name : Mongoid: using more than one database?

PS: I have also referred similar questions on stack overflow but some of them are for mysql db and I am not sure how I can use same thing for mongo db.

Praneetha
  • 303
  • 4
  • 17
  • 1
    If you have "referred the question" then I suggest you show us exactly why this does not suit you. And if you have be "referred before" then it's exactly for the same reason you are likely to here, being that you have not taken the time to "show" us what is so different about your problem. If you cannot do that, then I think you know what the likely outcome here is. I suggest you get busy editing your question with lots of detail about what you actually have done. – Neil Lunn May 22 '18 at 12:14
  • You can't really have two identically named models without conflicts. Can you not namespace them in different models. Or do you mean you have one model but need instances to point to different databases? – Kris May 22 '18 at 14:44
  • Hi @Kris, I have one model say, 'SampleModel' in one rails application say 'sample1' and I have another model with same name 'SampleModel' in another rails application say 'sample2'. Now I want to write a method in 'sample1' application which will actually use 'SampleModel' of 'sample2' application. Please let me know if any details are required. Thank you. – Praneetha May 22 '18 at 19:11
  • I would suggest to put the shared code in a gem/engine to share them between both applications. You could either share the entire model or add a module (called concern in Rails) which is included in both models. – Kris May 24 '18 at 08:41
  • The other option is an HTTP API between both applications, so you don't access the code in the other application directly but via HTTP like a regular request. – Kris May 24 '18 at 08:43

0 Answers0