In Mongoid (Rails) I have 3 models: File, Version and User. Version is embedded_in File, and both File and Version belongs_to a User (though not necessarily the same for all Versions in a File).
Now I want to retrieve all Versions that either belong to a specific User, or are embedded in a File that belongs to the same User.
I have tried:
- Pretty much anything
Version.<something>
, always 0 results (probably because Version is not a top level document?) File.any_of(user: user, 'versions.user': user)
: NoMethodError: undefined method `bson_type' for #<User:0x00000007cd9400>File.any_of(user: user, 'versions.user_id': user.id)
: Only returns Files that belong to the User, not Files that embed Versions belonging to the user
How can this be achieved in a database friendly way (not fetching all Files and iterating through their Versions)?