ruby on rails - Best practices for mongoid relations -
i mapping relations in mongoid, want know best practices mongoid.
models
- customer
- service
- supplier
there 4 different services (s1, s2, s3, s4), each service provided specific supplier. how can map these models or build relations among them?
thanks in advance.
you can either of these approaches, both supported mongoid:
referenced 1-n (aka
has_many)
in model, each service store_idof supplier provides it, similar typical rdbms.embedded 1-n (aka
embeds_many)
in model, each supplier document store internal data structure representing list of service(s) provides.
as schema decisions in mongodb, approach choose should largely based on use cases, , kinds of queries anticipate needing in application. question provides overview when embed vs. reference in mongodb:
see relations page of mongoid docs more details relationships in mongoid.
Comments
Post a Comment