我jenssegers/laravel-mongodb
在我的 Laravel MongoDB 应用程序中使用库。但是,这种 hasOne
关系只有foreignKey
在字符串中才有效。如果它保存为 ObjectId 类型,则该关系给出一个空结果。
MongoDB 文档 user_profile
{
"_id" : ObjectId("5c40307107928879107d8ee3"),
"first_name" : "Alert",
"last_name" : "CB",
"speciality" : null,
"company" : ObjectId("5b8cd8bc0176533ff65c4c62"),
"platform_start_date" : "2019-01-17",
"updated_at" : ISODate("2019-01-17T13:40:37.000+05:30"),
"created_at" : ISODate("2019-01-17T13:06:17.000+05:30")
}
公司文件
{
"_id" : ObjectId("5b8cd8bc0176533ff65c4c62"),
"name" : "ABCDEF",
"contact" : "Dani",
"notes" : "Test Note for builders....",
"updated_at" : ISODate("2018-09-03T12:16:20.000+05:30"),
"created_at" : ISODate("2018-09-03T12:16:20.000+05:30")
}
在 UserProfile 模型中
class UserProfile extends Moloquent
{
public function companies() {
return $this->hasOne('App\Models\Company', 'company', '_id' );
}
目前这companies()
给出了空数组,如何解决这个问题并得到结果?我正在使用 jenssegers/mongodb:3.4.2