我有" Vaga":
vaga.rb
class Vaga
include Mongoid::Document
has_and_belongs_to_many :areas, autosave: true
结果:
#<Vaga _id: 5524940d706f6c09180c0000, area_ids: [BSON::ObjectId('5524939b706f6c09180b0000'), BSON::ObjectId('5436721b706f6c0918cf0000')], titulo: "Ruby on Rails developer">
&#34; Area&#34; 的 area.rb
class Area
include Mongoid::Document
has_and_belongs_to_many :vagas
我怎样才能得到所有&#34; vagas&#34;有一系列&#34;区域&#34;?
我正在尝试这个:
vagas = Vaga.all('areas.id' => '5524939b706f6c09180b0000')
但它不会工作
答案 0 :(得分:3)
你可以试试这个
vagas = Vaga.where(area_ids: ['5524939b706f6c09180b0000'])
或强>
area = Area.where(id: '5524939b706f6c09180b0000').first
vagas = area.vagas
希望这有帮助!