@@ -48,7 +48,8 @@ protected function setUp(): void
48
48
49
49
Schema::create ('posts_tags ' , function (Blueprint $ table ) {
50
50
$ table ->integer ('post_id ' );
51
- $ table ->string ('tag_id ' );
51
+ $ table ->integer ('tag_id ' )->default (0 );
52
+ $ table ->string ('tag_name ' )->default ('' )->nullable ();
52
53
$ table ->string ('flag ' )->default ('' )->nullable ();
53
54
$ table ->timestamps ();
54
55
});
@@ -203,6 +204,7 @@ public function testCustomPivotClassUsingUpdateExistingPivot()
203
204
);
204
205
}
205
206
207
+ /** @group SkipMSSQL */
206
208
public function testCustomPivotClassUpdatesTimestamps ()
207
209
{
208
210
Carbon::setTestNow ('2017-10-10 10:10:10 ' );
@@ -402,8 +404,8 @@ public function testFindOrNewMethod()
402
404
403
405
$ this ->assertEquals ($ tag ->id , $ post ->tags ()->findOrNew ($ tag ->id )->id );
404
406
405
- $ this ->assertNull ($ post ->tags ()->findOrNew (' asd ' )->id );
406
- $ this ->assertInstanceOf (Tag::class, $ post ->tags ()->findOrNew (' asd ' ));
407
+ $ this ->assertNull ($ post ->tags ()->findOrNew (666 )->id );
408
+ $ this ->assertInstanceOf (Tag::class, $ post ->tags ()->findOrNew (666 ));
407
409
}
408
410
409
411
public function testFirstOrNewMethod ()
@@ -416,8 +418,8 @@ public function testFirstOrNewMethod()
416
418
417
419
$ this ->assertEquals ($ tag ->id , $ post ->tags ()->firstOrNew (['id ' => $ tag ->id ])->id );
418
420
419
- $ this ->assertNull ($ post ->tags ()->firstOrNew (['id ' => ' asd ' ])->id );
420
- $ this ->assertInstanceOf (Tag::class, $ post ->tags ()->firstOrNew (['id ' => ' asd ' ]));
421
+ $ this ->assertNull ($ post ->tags ()->firstOrNew (['id ' => 666 ])->id );
422
+ $ this ->assertInstanceOf (Tag::class, $ post ->tags ()->firstOrNew (['id ' => 666 ]));
421
423
}
422
424
423
425
public function testFirstOrCreateMethod ()
@@ -446,7 +448,7 @@ public function testUpdateOrCreateMethod()
446
448
$ post ->tags ()->updateOrCreate (['id ' => $ tag ->id ], ['name ' => 'wavez ' ]);
447
449
$ this ->assertSame ('wavez ' , $ tag ->fresh ()->name );
448
450
449
- $ post ->tags ()->updateOrCreate (['id ' => ' asd ' ], ['name ' => 'dives ' ]);
451
+ $ post ->tags ()->updateOrCreate (['id ' => 666 ], ['name ' => 'dives ' ]);
450
452
$ this ->assertNotNull ($ post ->tags ()->whereName ('dives ' )->first ());
451
453
}
452
454
@@ -598,6 +600,7 @@ public function testNoTouchingHappensIfNotConfigured()
598
600
$ this ->assertNotSame ('2017-10-10 10:10:10 ' , $ tag ->fresh ()->updated_at ->toDateTimeString ());
599
601
}
600
602
603
+ /** @group SkipMSSQL */
601
604
public function testCanRetrieveRelatedIds ()
602
605
{
603
606
$ post = Post::create (['title ' => Str::random ()]);
@@ -616,6 +619,7 @@ public function testCanRetrieveRelatedIds()
616
619
$ this ->assertEquals ([200 , 400 ], $ post ->tags ()->allRelatedIds ()->toArray ());
617
620
}
618
621
622
+ /** @group SkipMSSQL */
619
623
public function testCanTouchRelatedModels ()
620
624
{
621
625
$ post = Post::create (['title ' => Str::random ()]);
@@ -642,6 +646,7 @@ public function testCanTouchRelatedModels()
642
646
$ this ->assertNotSame ('2017-10-10 10:10:10 ' , Tag::find (300 )->updated_at );
643
647
}
644
648
649
+ /** @group SkipMSSQL */
645
650
public function testWherePivotOnString ()
646
651
{
647
652
$ tag = Tag::create (['name ' => Str::random ()]);
@@ -658,6 +663,7 @@ public function testWherePivotOnString()
658
663
$ this ->assertEquals ($ relationTag ->getAttributes (), $ tag ->getAttributes ());
659
664
}
660
665
666
+ /** @group SkipMSSQL */
661
667
public function testFirstWhere ()
662
668
{
663
669
$ tag = Tag::create (['name ' => 'foo ' ]);
@@ -674,6 +680,7 @@ public function testFirstWhere()
674
680
$ this ->assertEquals ($ relationTag ->getAttributes (), $ tag ->getAttributes ());
675
681
}
676
682
683
+ /** @group SkipMSSQL */
677
684
public function testWherePivotOnBoolean ()
678
685
{
679
686
$ tag = Tag::create (['name ' => Str::random ()]);
@@ -690,6 +697,7 @@ public function testWherePivotOnBoolean()
690
697
$ this ->assertEquals ($ relationTag ->getAttributes (), $ tag ->getAttributes ());
691
698
}
692
699
700
+ /** @group SkipMSSQL */
693
701
public function testWherePivotInMethod ()
694
702
{
695
703
$ tag = Tag::create (['name ' => Str::random ()]);
@@ -724,6 +732,7 @@ public function testOrWherePivotInMethod()
724
732
$ this ->assertEquals ($ relationTags ->pluck ('id ' )->toArray (), [$ tag1 ->id , $ tag3 ->id ]);
725
733
}
726
734
735
+ /** @group SkipMSSQL */
727
736
public function testWherePivotNotInMethod ()
728
737
{
729
738
$ tag1 = Tag::create (['name ' => Str::random ()]);
@@ -762,6 +771,7 @@ public function testOrWherePivotNotInMethod()
762
771
$ this ->assertEquals ($ relationTags ->pluck ('id ' )->toArray (), [$ tag1 ->id , $ tag2 ->id ]);
763
772
}
764
773
774
+ /** @group SkipMSSQL */
765
775
public function testWherePivotNullMethod ()
766
776
{
767
777
$ tag1 = Tag::create (['name ' => Str::random ()]);
@@ -779,6 +789,7 @@ public function testWherePivotNullMethod()
779
789
$ this ->assertEquals ($ relationTag ->getAttributes (), $ tag2 ->getAttributes ());
780
790
}
781
791
792
+ /** @group SkipMSSQL */
782
793
public function testWherePivotNotNullMethod ()
783
794
{
784
795
$ tag1 = Tag::create (['name ' => Str::random ()]);
@@ -853,17 +864,17 @@ public function testCustomRelatedKey()
853
864
$ post = Post::create (['title ' => Str::random ()]);
854
865
855
866
$ tag = $ post ->tagsWithCustomRelatedKey ()->create (['name ' => Str::random ()]);
856
- $ this ->assertEquals ($ tag ->name , $ post ->tagsWithCustomRelatedKey ()->first ()->pivot ->tag_id );
867
+ $ this ->assertEquals ($ tag ->name , $ post ->tagsWithCustomRelatedKey ()->first ()->pivot ->tag_name );
857
868
858
869
$ post ->tagsWithCustomRelatedKey ()->detach ($ tag );
859
870
860
871
$ post ->tagsWithCustomRelatedKey ()->attach ($ tag );
861
- $ this ->assertEquals ($ tag ->name , $ post ->tagsWithCustomRelatedKey ()->first ()->pivot ->tag_id );
872
+ $ this ->assertEquals ($ tag ->name , $ post ->tagsWithCustomRelatedKey ()->first ()->pivot ->tag_name );
862
873
863
874
$ post ->tagsWithCustomRelatedKey ()->detach (new Collection ([$ tag ]));
864
875
865
876
$ post ->tagsWithCustomRelatedKey ()->attach (new Collection ([$ tag ]));
866
- $ this ->assertEquals ($ tag ->name , $ post ->tagsWithCustomRelatedKey ()->first ()->pivot ->tag_id );
877
+ $ this ->assertEquals ($ tag ->name , $ post ->tagsWithCustomRelatedKey ()->first ()->pivot ->tag_name );
867
878
868
879
$ post ->tagsWithCustomRelatedKey ()->updateExistingPivot ($ tag , ['flag ' => 'exclude ' ]);
869
880
$ this ->assertSame ('exclude ' , $ post ->tagsWithCustomRelatedKey ()->first ()->pivot ->flag );
@@ -903,6 +914,7 @@ public function testPivotDoesntHavePrimaryKey()
903
914
$ this ->assertEquals (0 , $ user ->postsWithCustomPivot ()->first ()->pivot ->is_draft );
904
915
}
905
916
917
+ /** @group SkipMSSQL */
906
918
public function testOrderByPivotMethod ()
907
919
{
908
920
$ tag1 = Tag::create (['name ' => Str::random ()]);
@@ -935,6 +947,7 @@ class User extends Model
935
947
protected static function boot ()
936
948
{
937
949
parent ::boot ();
950
+
938
951
static ::creating (function ($ model ) {
939
952
$ model ->setAttribute ('uuid ' , Str::random ());
940
953
});
@@ -959,6 +972,7 @@ class Post extends Model
959
972
protected static function boot ()
960
973
{
961
974
parent ::boot ();
975
+
962
976
static ::creating (function ($ model ) {
963
977
$ model ->setAttribute ('uuid ' , Str::random ());
964
978
});
@@ -1013,7 +1027,7 @@ public function tagsWithCustomAccessor()
1013
1027
1014
1028
public function tagsWithCustomRelatedKey ()
1015
1029
{
1016
- return $ this ->belongsToMany (Tag::class, 'posts_tags ' , 'post_id ' , 'tag_id ' , 'id ' , 'name ' )
1030
+ return $ this ->belongsToMany (Tag::class, 'posts_tags ' , 'post_id ' , 'tag_name ' , 'id ' , 'name ' )
1017
1031
->withPivot ('flag ' );
1018
1032
}
1019
1033
0 commit comments