“self” here stands for Contact model.
This query will find all completed tasks for a contact.
The Task model has a field/key :assigned_contacts of type Array.
So the query is searching inside the Array.
def assigned_tasks_completed
self.company.tasks.all(:assigned_contacts => self.id.to_s, :completed => true)
end
How to do this in Mongoid?
Another question:
The equivalent in Mongoid of @contact.set(:a -> a, :b -> b, :c -> c) is update_attributes!
But there is also a method set in Mongoid.
What is the difference between set & update_attributes! in Mongoid ?
I assume your tasks is a separate document. So you can just replace
allwithwhere, it will workFor your another question,
Both mongoid set & update attributes are internally uses mongodb $set. But the difference is mongoid set is only accepts single field update, update_attributes accepts multiple.