I have three Models: User, Picture, and Like
where:
class Picture
include Mongoid::Document
embeds_many :likes
belongs_to :user
end
class User
include Mongoid::Document
has_many :pictures
has_many :likes
end
class Like
include Mongoid::Document
belongs_to :user
embedded_in :picture
end
No I want to store the likes to then:
- See how many likes have a picture ( Picture.first.likes.count )
- See how many likes a user has ( User.first.likes.count )
- See to what picture the user make a like?
Is this Schema correct to achieve the three requires?
First thing the embedded model can’t be referenced in other like you have tried for Like(which is already embedded in picture) to be referenced in User.
The correct model structure will be
now answer to your queries