在我的控制器中: - $ data = Favouriteignored :: with(' favusers');
在我的模型中收藏
public function favusers() {
return $this->belongsTo('Usermanage', 'type_member_id','_id');
}
收藏favouriteignoredmembers文件: -
{
"__v": NumberInt(0),
"_id": ObjectId("54e5dce5b1e7b4018aa6ea86"),
"type": {
"favourite": "1",
"ignored": "0"
},
"type_member_id": ObjectId("54a5360be1f44e1e378b4567"),
"user_id": ObjectId("54b6162cf56c0de40e8b4567")
}
成员收集文件: -
{
"_id": ObjectId("54a5360be1f44e1e378b4567"),
"active": "1",
"address": "test",
"cell_number": "8888",
"city": "test",
"company": "test",
"confirmation_code": "u74Vs0xJXna5RHZQz7DZTnY2XfKNzH",
"country": "India",
"department": "t",
"email": "g@g.com",
"first_name": "Gaurav",
"gender": "male",
"image": "52759b.jpg",
"image_name": "",
"is_deleted": "0",
"last_login": "2015/02/19 12:50:07",
"last_name": "handa",
"password": "$2y$10$fm0KsS0MX50VRWC9HIiTAumU5FU1qZIztxCkn/e9dbZuF2Tf7PwBy",
"remember_token": "hN4n8eGALMXTs84Tub0qrgnqVlrDd1WDBHcKh8VDBLFs43wRA4GILL3OJDiy",
"state": "test",
"telephone_number": "123",
"title": "t",
"username": "t",
"verified": "1",
"via": "login",
"zip_code": "test"
}
现在我在" type_member_id"的基础上将favouriteignored集合与成员集合相关联。作为外国人的关键和成员收集的_id。
使用外键和本地键作为mongodb的ObjectId。 无法获得结果。如果我将type_member_id保持为字符串,它可以正常工作。
提前致谢。
答案 0 :(得分:0)
我认为这可能是一个错误。我注意到,当外键是一个字符串时,我的关系也很好用。 ObjectId有时可以工作但不是全部