Skip to content

Commit

Permalink
Merge branch 'postgres-support' of https://github.com/kirschbaum-deve…
Browse files Browse the repository at this point in the history
…lopment/eloquent-power-joins into postgres-support
  • Loading branch information
danharrin committed Oct 2, 2024
2 parents 61236d0 + 66dd83e commit b7b98b0
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 119 deletions.
29 changes: 14 additions & 15 deletions tests/JoinRelationshipExtraConditionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ public function test_join_belongs_to_with_additional_conditions()
$query = Post::query()->joinRelationship('userWithTrashed')->toSql();
$posts = Post::query()->joinRelationship('userWithTrashed')->get();


$this->assertStringContainsString(
$this->assertQueryContains(
'inner join "users" on "posts"."user_id" = "users"."id"',
$query
);
Expand All @@ -46,12 +45,12 @@ public function test_join_belongs_to_with_additional_conditions_and_alias()

$this->assertCount(1, $posts);

$this->assertStringContainsString(
$this->assertQueryContains(
'."rockstar" = ?',
$query
);

$this->assertStringNotContainsString(
$this->assertQueryNotContains(
'and "users"."rockstar" = ?',
$query
);
Expand All @@ -69,12 +68,12 @@ public function test_join_has_many_relationship_with_additional_conditions()
$this->assertCount(1, $categories);
$this->assertEquals($category1->id, $categories->first()->id);

$this->assertStringContainsString(
$this->assertQueryContains(
'inner join "posts" on "posts"."category_id" = "categories"."id"',
$query
);

$this->assertStringContainsString(
$this->assertQueryContains(
'and "posts"."published" = ?',
$query
);
Expand All @@ -97,7 +96,7 @@ public function test_join_has_many_relationship_with_additional_conditions_and_a
$query
);

$this->assertStringContainsString(
$this->assertQueryContains(
'."published" = ?',
$query
);
Expand All @@ -116,12 +115,12 @@ public function test_join_has_one_relationship_with_additional_conditions()
$this->assertCount(1, $users);
$this->assertEquals($user1->id, $users->first()->id);

$this->assertStringContainsString(
$this->assertQueryContains(
'inner join "user_profiles" on "user_profiles"."user_id" = "users"."id"',
$query
);

$this->assertStringContainsString(
$this->assertQueryContains(
'and "city" is not null',
$query
);
Expand All @@ -141,7 +140,7 @@ public function test_extra_conditions_with_belongs_to_many()
$this->assertCount(2, Group::joinRelationship('posts')->get());
$this->assertCount(1, Group::joinRelationship('publishedPosts')->get());

$this->assertStringContainsString(
$this->assertQueryContains(
'inner join "posts" on "posts"."id" = "post_groups"."post_id" and "posts"."deleted_at" is null and "posts"."published" = ?',
Group::joinRelationship('publishedPosts')->toSql()
);
Expand All @@ -163,7 +162,7 @@ public function test_extra_conditions_in_pivot_with_belongs_to_many_in()
$this->assertCount(3, Group::joinRelationship('posts')->get());
$this->assertCount(2, Group::joinRelationship('recentPosts')->get());

$this->assertStringContainsString(
$this->assertQueryContains(
'inner join "posts" on "posts"."id" = "post_groups"."post_id" and "posts"."deleted_at" is null and "post_groups"."assigned_at" >= ?',
Group::joinRelationship('recentPosts')->toSql()
);
Expand All @@ -180,7 +179,7 @@ public function test_extra_conditions_in_morph_many()

$this->assertCount(1, $posts);

$this->assertStringContainsString(
$this->assertQueryContains(
'inner join "images" on "images"."imageable_id" = "posts"."id" and "images"."imageable_type" = ? and "cover" = ?',
$query
);
Expand All @@ -202,12 +201,12 @@ public function test_extra_conditions_in_morph_to_many()
$this->assertCount(1, $postsQuery->get());
$this->assertCount(1, $commentsQuery->get());

$this->assertStringContainsString(
$this->assertQueryContains(
'inner join "taggables" on "taggables"."taggable_id" = "posts"."id" and "taggables"."taggable_type" = ?',
$postsQuery->toSql()
);

$this->assertStringContainsString(
$this->assertQueryContains(
'inner join "taggables" on "taggables"."taggable_id" = "comments"."id" and "taggables"."taggable_type" = ?',
$commentsQuery->toSql()
);
Expand Down Expand Up @@ -238,7 +237,7 @@ public function test_extra_conditions_with_closure()
$query = User::joinRelationship('publishedOrReviewedPosts')->toSql();
User::joinRelationship('publishedOrReviewedPosts')->get();

$this->assertStringContainsString(
$this->assertQueryContains(
'inner join "posts" on "posts"."user_id" = "users"."id" and "posts"."deleted_at" is null and ("published" = ? or "reviewed" = ?)',
$query
);
Expand Down
Loading

0 comments on commit b7b98b0

Please sign in to comment.