pirmax
pirmax

Reputation: 2153

Laravel 5.5 : MongoDB & hasManyThrough() relation

I use MongoDB with Laravel: https://github.com/jenssegers/laravel-mongodb

I have two tables (feeds, users) and a collection on MongoDB (articles) that come in this form:

articles (MongoDB):

  • _id (ObjectID)
  • feed_id
  • title

feeds (MySQL):

  • id
  • user_id
  • name

users (MySQL):

  • id
  • name

I would like to retrieve all the articles of a user while passing by "feeds".

For this, I use the hasManyThrough() relation in the User model:

public function articles()
    {
        return $this->hasManyThrough(
            Article::class,
            Feed::class,
            'user_id',
            'feed_id',
            '_id',
            'id'
        );
    }

But the problem is that on each user, I have the same articles listed, it looks like it does not take into account user_id...

Upvotes: 1

Views: 481

Answers (1)

Andranik Petrosyan
Andranik Petrosyan

Reputation: 92

https://github.com/jenssegers/laravel-mongodb package not supporting $this->hasManyThrough - relation .

Relations Supported relations are:

  1. hasOne
  2. hasMany
  3. belongsTo
  4. belongsToMany
  5. embedsOne
  6. embedsMany

You can check documentation : https://github.com/jenssegers/laravel-mongodb

Upvotes: 1

Related Questions