-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hybrid support for BelongsToMany relationship #2688
Hybrid support for BelongsToMany relationship #2688
Conversation
Co-Authored-By: Junio Hyago <35033754+juniohyago@users.noreply.github.com>
Co-Authored-By: Junio Hyago <35033754+juniohyago@users.noreply.github.com>
The relation data of the current eloquent model instance doesn't update. It has to be fixed to prevent users from fetching the latest relationship data from DB each time or it's possible to make users confused. |
@@ -51,5 +57,12 @@ public static function executeSchema(): void | |||
$table->string('name'); | |||
$table->timestamps(); | |||
}); | |||
if (! $schema->hasTable('skill_sql_user')) { | |||
$schema->create('skill_sql_user', function (Blueprint $table) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want to have a pivot table here? If the relations are already stored in the MongoDB document, it should not be duplicated in an SQL table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
laravel-mongodb/src/Eloquent/HybridRelations.php
Lines 290 to 301 in fc1f9cc
// Check if it is a relation with an original model. | |
if (! is_subclass_of($related, MongoDBModel::class)) { | |
return parent::belongsToMany( | |
$related, | |
$collection, | |
$foreignPivotKey, | |
$relatedPivotKey, | |
$parentKey, | |
$relatedKey, | |
$relation, | |
); | |
} |
The sql models don't reach our BelongsToMany
class. So, we can't control this behavior.
As I know, the sql models, store their relations data in a pivot tabel and mongo models, store theirs in a pivot column.
Hi @GromNaN, Could you please merge these two PRs? |
It seems feasible today. |
It would be awesome😁🔥 |
Thank you @hans-thomas. I'm merging the other one and wait for your new PR. |
Hi, I noticed the lines that we removed in #2664 (comment) PR, were part of handling the hybrid relationship that was not covered by tests.
This PR is continuing #2276. Thanks to @juniohyago.