I am using Mongoid for the first time. I want to store a collection of emails that have a subject, body, and arrays of to, cc, and bcc recipients. Example:
{to: [{email: 'andrew@example.com', name: 'Andrew'}], cc: ...
However, I can’t seem to figure out how to model this data using Mongoid. I think the term for these are called embedded documents, but everything I’ve tried does not seem to work right. How do I create my models correctly with Mongoid?
Here is the solution. You can specify class name if you want to reuse a class for multiple fields: