[5.8] Fix BelongsToMany read wrong parent key.#28317
Merged
taylorotwell merged 1 commit intolaravel:5.8from Apr 25, 2019
Merged
[5.8] Fix BelongsToMany read wrong parent key.#28317taylorotwell merged 1 commit intolaravel:5.8from
taylorotwell merged 1 commit intolaravel:5.8from
Conversation
Member
|
Shouldn't it be the following instead? (actual shop uuid) delete from `user_shop` where (`user_uuid` = 'c3b5c66a-aebe-4c76-9a51-9c305ff6dad1' and `shop_uuid` = '25adf508-8dff-4a7f-ad26-3320f4d23f15')Your examples are a little confusing since you use twice the same primary key and uuid for your shop records. Can you paste your full user and shop model? |
Member
|
@staudenmeir can you maybe confirm this pr? |
Contributor
Author
|
@driesvints Sorry for my typo. Actually the first shop uuid is '25adf508-8dff-4a7f-ad26-3320f4d23f15'; Here is my full Models. User <?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
public $timestamps = false;
public function shops()
{
return $this->belongsToMany(Shop::class, 'user_shop', 'user_uuid',
'shop_uuid', 'uuid', 'uuid')
->using(UserShop::class);
}
}Shop <?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Shop extends Model
{
public $timestamps = false;
}UserShop <?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\Pivot;
class UserShop extends Pivot
{
}You can also run the test case to reproduce this bug. |
staudenmeir
approved these changes
Apr 24, 2019
themsaid
approved these changes
Apr 25, 2019
driesvints
approved these changes
Apr 25, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sometimes we don't have primary id in pivot table. For example:
I have three tables.
User extends Eloquent\Model
UserShop extends Eloquent\Relations\Pivot
// Emptyexpect
actual
Because
user_uuidread$this->parent->getKey().