2

Hello Good Developers,

I am trying to implement embedsMany relationship of jenssegers/laravel-mongodb

I have two collections:

  • ProfileSection - { "_id": "5c865ea4257db43fe4007331", "general_name": "MY_PROFILE", "type": "public", "points": 100, "status": 1, "translated": [ { "con_lang": "US-EN", "country_code": "US", "language": "EN", "text": "My Profile", "description": "My Profile" }, ... ], "updated_at": "2019-03-11T13:12:04.000Z", "created_at": "2019-03-11T13:12:04.000Z" }
  • Profile Questions - { "_id": "5c865ea3257db43fe40072b2", "id": "STANDARD_EDUCATION", "general_name": "STANDARD_EDUCATION", "country_code": "US", "order": 1, "profile_section_id": "5c865ea4257db43fe4007331", "profile_section": "My Profile", "translated": [ { "con_lang": "US-EN", "text": "What is the highest level of education you have completed?", "hint": null, "mapping": {}, "answers": [ { "precode": "1", "text": "3rd Grade or less", "mapping": {} } ] }, {...} ], "updated_at": "2019-03-11T13:12:03.000Z", "created_at": "2019-03-11T13:12:03.000Z" }

In ProfileSection I have added

public function questions()  
{  
    return $this->embedsMany(ProfilerQuestions::class, '_id', 'profile_section_id');  
}

If I execute ProfileSection::find('5c865ea4257db43fe4007331')->questions It returns me Profile Questions Object with only one attribute: 5c865ea4257db43fe4007331 i.e ObjectId of Profile Section

enter image description here

I tried using ->with('questions) before accessing questions object like this but it's not working

I don't understand what's the issue will definitely need some help.

Pankaj Jha
  • 886
  • 15
  • 37

0 Answers0