So lets say I have an Entities Model which is the base for a People and Organizations Model.
I\'ve three empty collections, one for Entities, one for People, one for
I got the code to work with a few edits. I'm only showing the People entity for brevity, but it applies to the Organizations block also. The edit is where the filter saves the People model to the database.
From:
if(isset($record->person_data)) {
$person = People::create($record->person_data);
if($person->save()) {
$record->person_id = $person->id;
}
}
To:
if(isset($record->person_data)) {
//added this to make an array out of the $record->person_data(mongo doc)
//$person_data = array();
//foreach($record->person_data as $key => $value) {
//$person_data[$key] = $value;
//}
//replaced the mongo doc with the array
//Edited: accessing the data() method on an object will return an array of the properties, doing exactly what I put up there initially.
$person = People::create($record->person_data->data());
if($person->save()) {
//replaced the "id" with "_id"
$record->person_id = $person->_id;
}
//removed the person_data embedded doc from the entity doc
unset($record->person_data);
}