-
Notifications
You must be signed in to change notification settings - Fork 1.5k
-
- Laravel-mongodb Version: dev-develop
- PHP Version: 7
- Database Driver & Version: atlas
Description:
Ok I have been working on this for three days with no results, I have to assume at this point that there might be bug that is causing this.
I am setting up an extremely simple relation hasOne
// Categories
{
_id: ObjectId('5c8445700000000000000000'),
name: 'Foo',
description: 'Test foo'
}
// Posts
{
_id: ObjectId('5c8445700000000000000001'),
name: 'Bar',
text: 'Test foo',
category_id: ObjectId('5c8445700000000000000000')
}
The Controller Code
protected $collection = 'category';
protected $primaryKey = '_id';
protected $guarded = [];
protected $casts = [
'category_id' => 'string',
];
public function category()
{
return $this->hasOne(Categories::class, '_id', 'category_id');
}
Blade
$category = Categories::where('name', 'Foo')->first();
dd($category->parent());
No matter what I did or tried the result relation is always empty.
Anybody has any ideas?
Beta Was this translation helpful? Give feedback.
All reactions
Hello,
Why are you using dev-develop version and not the latest stable ones?
Thanks!
Replies: 1 comment 3 replies
-
Hello,
Why are you using dev-develop version and not the latest stable ones?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions
-
Please try reading relations documentation again.
You need to understand parent children relation and use correct function to get children instead of getting parent from parent.
Beta Was this translation helpful? Give feedback.
All reactions
-
Not sure why it was dev but I just did an composer update and installed 3.7 but still not results.
I am confused all I am looking to do is to get all the posts of a category. The issues with the documentation is that it does not show how the collection needs to be set up. It notes that hasOne should work maybe I am missing something.
Beta Was this translation helpful? Give feedback.
All reactions
-
Never mind I had to restart the server I realized that I had npm run watch still on. I guess the dev version might have been it. Thank you
Beta Was this translation helpful? Give feedback.