I have User
, Shop
and FavouriteShop
models. I'm using mongoid:
class User
include Mongoid::Document
has_many :favourite_shops, dependent: :destroy
end
class Shop
include Mongoid::Document
has_many :favourite_shops, dependent: :destroy
end
class FavouriteShop
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :user
belongs_to :shop
end
As you can see, there is many-to-many relationship with User
and Shop
via FavouriteShop
.
Now If I got one user:
user = User.all.first
How can I get all Shops which are associatied to User?