Skip to content

Commit f3fab09

Browse files
author
Hikmat Hasanov
committed
override getQualifiedForeignKeyName() and add tests for whereBelongsTo
1 parent 61cc6ed commit f3fab09

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Relations/BelongsTo.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,12 @@ protected function whereInMethod(EloquentModel $model, $key)
7272
{
7373
return 'whereIn';
7474
}
75+
76+
/**
77+
* @return string
78+
*/
79+
public function getQualifiedForeignKeyName()
80+
{
81+
return $this->foreignKey;
82+
}
7583
}

tests/RelationsTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,4 +534,17 @@ public function testDoubleSaveManyToMany(): void
534534
$this->assertEquals([$user->_id], $client->user_ids);
535535
$this->assertEquals([$client->_id], $user->client_ids);
536536
}
537+
538+
public function testWhereBelongsTo()
539+
{
540+
$user = User::create(['name' => 'John Doe']);
541+
Item::create(['user_id' => $user->_id]);
542+
Item::create(['user_id' => $user->_id]);
543+
Item::create(['user_id' => $user->_id]);
544+
Item::create(['user_id' => null]);
545+
546+
$items = Item::query()->whereBelongsTo($user)->get();
547+
548+
$this->assertCount(3, $items);
549+
}
537550
}

0 commit comments

Comments
 (0)