@@ -70,15 +70,32 @@ protected function tearDown(): void
7070
7171 public function testItGuessesRelationName ()
7272 {
73- $ user = HasOneOfManyTestUser::create ();
73+ $ user = HasOneOfManyTestUser::make ();
7474 $ this ->assertSame ('latest_login ' , $ user ->latest_login ()->getRelationName ());
7575 }
7676
77- // public function testRelationNameCanBeSet()
78- // {
79- // $user = HasOneOfManyTestUser::create();
80- // $this->assertSame('foo', $user->latest_login_with_other_name()->getRelationName());
81- // }
77+ public function testItGuessesRelationNameAndAddsOfManyWhenTableNameIsRelationName ()
78+ {
79+ $ model = HasOneOfManyTestModel::make ();
80+ $ this ->assertSame ('logins_of_many ' , $ model ->logins ()->getRelationName ());
81+ }
82+
83+ public function testRelationNameCanBeSet ()
84+ {
85+ $ user = HasOneOfManyTestUser::create ();
86+
87+ // Using "ofMany"
88+ $ relation = $ user ->latest_login ()->ofMany ('id ' , 'max ' , 'foo ' );
89+ $ this ->assertSame ('foo ' , $ relation ->getRelationName ());
90+
91+ // Using "latestOfMAny"
92+ $ relation = $ user ->latest_login ()->latestOfMAny ('id ' , 'bar ' );
93+ $ this ->assertSame ('bar ' , $ relation ->getRelationName ());
94+
95+ // Using "oldestOfMAny"
96+ $ relation = $ user ->latest_login ()->oldestOfMAny ('id ' , 'baz ' );
97+ $ this ->assertSame ('baz ' , $ relation ->getRelationName ());
98+ }
8299
83100 public function testQualifyingSubSelectColumn ()
84101 {
@@ -225,9 +242,6 @@ public function testIsNotMethod()
225242 $ this ->assertFalse ($ user ->latest_login ()->isNot ($ login2 ));
226243 }
227244
228- /**
229- * @group fail
230- */
231245 public function testGet ()
232246 {
233247 $ user = HasOneOfManyTestUser::create ();
@@ -392,6 +406,14 @@ public function price_with_shortcut()
392406 }
393407}
394408
409+ class HasOneOfManyTestModel extends Eloquent
410+ {
411+ public function logins ()
412+ {
413+ return $ this ->hasOne (HasOneOfManyTestLogin::class)->ofMany ();
414+ }
415+ }
416+
395417class HasOneOfManyTestLogin extends Eloquent
396418{
397419 protected $ table = 'logins ' ;
0 commit comments