I have a mongoid model called Department and a separate model called User, and there is no native relationship between the two models. Because of how the relationships in my application work, I manually store document ID's on the User model.
I am using the Grape framework for Ruby, and it has a filter system that sits on top of Mongoid objects called Entities, and it rejects anything that isnt a mongoid query response object, because this method returns a ruby Array instead of a Mongoid object, my framework gives me errors.
Is there any way to re write my function to return a Mongoid object? or is there any way I can convert an array of Mongoid Objects into one Mongoid object?
## inside Department Model
def self.user_can_access(user = nil)
if user != nil
departments = []
## department_access_keys are embedded documents belonging to a user
user.department_access_keys.each do |key|
departments << BACKBONE::Department.find(key.key)
end
departments ## => returns an array of Department Documents that a user has been granted access to
else
raise 'user was not defined'
end
end