1

I have two models

Class FirstModel
  embeds_one :second_model, class_name: 'V1::SecondModel'

Class SecondModel
  embedded_in :first_model, class_name 'V1::FirstModel'

I have some records of first model and I can get second model records from first models object in my rails c console as firstmodelobj.second_model

I have googled and tried enough but I can't seem to find the first model(parent) object from the second model(child) object's id.

Thanks in advance.

Subash
  • 3,128
  • 6
  • 30
  • 44

1 Answers1

0

found it,

V1::FirstModel.where("second_model._id" => Moped::BSON::ObjectId("id")).first
Subash
  • 3,128
  • 6
  • 30
  • 44