I have models like bellow. i want to query events for user with different kind of statuses by guests 'list'. If am not wrong guests list should be embeded in events? If my model design are wrong i`m open for different solution.
class User
include Mongoid::Document
end
class Events
include Mongoid::Document
embeds_many :guests
end
Class Guests
include Mongoid::Document
embed_in :event
belongs_to :user
field :status
end
I believe that model structure would work.
Here's an example query to get all events with guests with the 'waiting' status:
Here's another example to, given an event, get all that event's guests with 'waiting' status:
Finally, you should name your models singular names (User, Event, Guest). Also, your Guest model has some typos I fixed below:
The model structure is wrong as in
Mongo
you only keep the information in embedded documents which are required only in parent document.If in guests you have only status field, then you can try this,e.g., two status type present or not present
then you can query with the status like