I’m having trouble figuring out how to use BelongsToMany between my MySQL DB and Mongo DB (if this is possible).
I have the following setup:
projects (MySQL) with “id” field
project_task (MySQL) with “project_id” (unsigned bit int) and “task_id” (string) fields
tasks (MongoDB) with “_id” (ObjectId) field.
As for my models, I have
Project extending the Illuminate\Database\Eloquent\model; and using the MongoDB\Laravel\Eloquent\HybridRelationships; trait
public function tasks(): BelongsToMany
{
return $this->belongsToMany(Task::class, ‘project_task’, ‘task_id’, ‘project_id’);
}
Task class extending MongoDB\Laravel\Eloquent\Model; and using the MongoDB\Laravel\Eloquent\HybridRelationships; trait.
public function projects(): BelongsToMany
{
return $this->belongsToMany(Project::class, ‘project_task’, ‘task_id’, ‘project_id’);
}
I have good reason to keep tasks in mongo and projects not, but is it possible to use this trait with pivot tables, and if so what am I doing wrong, as with valid DB entries, this returns no results.