0

I have 4 models, User(Postgres), Subscription(Mongo), Podcast (Mongo), and Newspaper (Mongo). A user can have multiple podcasts through subscriptions and a podcast can have multiple users through subscription. A subscription also has fees field with it. How can I implement has_many_through & polymorphic association in this scenario? Stub:

class User < ActiveRecord::Base
end  


 class Podcast
  include Mongoid::Document
 end



class Newspaper
  include Mongoid::Document
 end



class Subscription
  include Mongoid::Document
  field :fees
 end

Thanks in advance! :)

hamxa_19
  • 1
  • 1

2 Answers2

0

AR and Mongoid are completely separate projects. Although they present a similar API, the internals are completely different in most cases.

To link AR and Mongoid data you need to write appropriate code in your application. You can use the methods provided by each data access layer to assist but there isn't a magic solution that links the two.

D. SM
  • 13,584
  • 3
  • 12
  • 21
0

I forgot to include Active Record Bridge. Basically, it is used for linking AR models with Mongo's Documents.

include Mongoid::ActiveRecordBridge
hamxa_19
  • 1
  • 1