Reputation: 14029
I find a lot of documentation on the internet about eager loading and optimisations for ActiveRecord, not so much about mongoid.
I'd like to think everything works the same, but that would be too easy, and probably totally wrong in some cases. There are some key differences bewteen ActiveRecord and Mongoid (and not just the embedded stuff), and I'd like to know... what I should know in order to determine whether what I read can also apply to Mongoid or not.
For instance, this link is one of my first results in Google. Can I assume everything that is said about includes
, preload
, and eager_load
can also apply to Mongoid ?
If I want to pull a lot of deep-nested information, how should I proceed for Mongoid ?
Upvotes: 0
Views: 434
Reputation: 11429
There is no simple answer to this question. For starters, the link you gave references functions that use joins
which are not available in Mongoid, so that information explicitly does not apply when using Mongoid.
A couple other examples that come to mind: Mongoid allows you to store Hash and Array fields directly on a document. Activerecord can only store pseudo arrays via serialization. Mongoid has_has_many_and_belongs_to_many
scales horrendously (which is not explained anywhere, it's just something you would learn if you implemented it), whereas that relation is fantastic when used with Activerecord.
The truth is that your application architecture should vary somewhat (possibly drastically) depending on whether you decide to build with Mongoid or Activerecord. Both have benefits and weaknesses.
Upvotes: 1