Skip to content

Commit a65cbbc

Browse files
laylatichygitbutler-client
authored andcommitted
test: fix belongs to many alias and add join test
1 parent 2a11aec commit a65cbbc

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

tests/Integration/Database/ModelInspector/BelongsToManyTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,26 @@ public function test_belongs_to_many_with_parent(): void
5454
->setParent(name: 'parent');
5555

5656
$this->assertSame(
57-
expected: 'target.data AS `parent.targets.data`',
57+
expected: 'parent_targets.data AS `parent.targets.data`',
5858
actual: $relation->getSelectFields()[1]->compile(DatabaseDialect::SQLITE),
5959
);
6060
}
6161

62+
public function test_belongs_to_many_with_parent_join_uses_alias(): void
63+
{
64+
$model = inspect(model: BelongsToManyOwnerModel::class);
65+
$relation = $model
66+
->getRelation(name: 'targets')
67+
->setParent(name: 'parent');
68+
69+
$this->assertSame(
70+
expected: 'LEFT JOIN owner_target ON owner_target.owner_id = owner.id LEFT JOIN target AS parent_targets ON parent_targets.id = owner_target.target_id',
71+
actual: $relation
72+
->getJoinStatement()
73+
->compile(dialect: DatabaseDialect::SQLITE),
74+
);
75+
}
76+
6277
public function test_belongs_to_many_with_custom_pivot(): void
6378
{
6479
$model = inspect(model: BelongsToManyCustomOwnerModel::class);

0 commit comments

Comments
 (0)