Skip to content

Many to Many Hybrid relationship #1635

@lucabartoli

Description

@lucabartoli

My code (not relevant parts omitted):

class User extends Authenticatable
{
    use Notifiable;
    use HybridRelations;
    protected $connection = 'mysql';

    public function messages()
    {
        return $this->belongsToMany(Message::class);
    }
}
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
use App\Models\User;

class Message extends Eloquent
{
    protected $connection = 'mongodb';
    protected $collection = 'messages';

    public function users()
    {
        return $this->belongsToMany(User::class);
    }
}

Now:

Message::first()->users()->attach( User::first() ); //Stores in the pivot table in MySQL
User::first()->messages()->attach( Message::first() ); //Stores in the embedded relation in MongoDB

The issue now is that I'm only able to retrieve the users from a message (if I used the first method) OR viceversa.

Is it possible to specify the connection on which the relation is stored?
So I would be able to update and read both object from both the relations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions