Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 3.0.2 #36

Merged
merged 10 commits into from
Mar 9, 2024
2 changes: 1 addition & 1 deletion .github/workflows/styles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Configure PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Configure PHP
uses: shivammathur/setup-php@v2
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"phpunit/phpunit": "^10.5",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/extension-installer": "^1.3",
"roots/wordpress": "6.4",
"roots/wordpress": "6.4.3",
"rector/rector": "1.0.2"
},
"config": {
Expand Down
4 changes: 2 additions & 2 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:base",
"config:recommended",
":disableDependencyDashboard"
],
"minimumReleaseAge": "30 days",
"labels": ["dependencies"],
"prConcurrentLimit": 5,
"baseBranches": ["develop"],
"assignees": ["dimitriBouteille"]
}
}
3 changes: 2 additions & 1 deletion src/Builders/AbstractWithMetaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Dbout\WpOrm\Exceptions\WpOrmException;
use Dbout\WpOrm\MetaMappingConfig;
use Dbout\WpOrm\Orm\AbstractModel;
use Dbout\WpOrm\Orm\Database;
use Illuminate\Database\Eloquent\Model;

/**
Expand Down Expand Up @@ -128,7 +129,7 @@ public function joinToMeta(string $metaKey, string $joinType = 'inner'): self
$join->on(
sprintf('%s.%s', $metaKey, $this->metaConfig?->columnKey),
'=',
"$metaKey"
Database::getInstance()->raw(sprintf("'%s'", $metaKey))
)->on(
sprintf('%s.%s', $metaKey, $this->metaConfig?->foreignKey),
'=',
Expand Down
68 changes: 32 additions & 36 deletions tests/Builders/WithMetaBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,19 @@ public function testAddMetaToSelect(string $metaKey, ?string $alias, string $exp
}

/**
* @return array
* @return \Generator
*/
public static function providerTestAddMetaToSelect(): array
public static function providerTestAddMetaToSelect(): \Generator
{
return [
'Without alias' => [
'my_meta',
null,
'select "posts".*, "my_meta"."meta_value" as "my_meta_value" from "posts" inner join "postmeta" as "my_meta" on "my_meta"."meta_key" = "my_meta" and "my_meta"."post_id" = "posts"."ID"',
],
'With alias' => [
'first_name',
'my_custom_alias',
'select "posts".*, "first_name"."meta_value" as "my_custom_alias" from "posts" inner join "postmeta" as "first_name" on "first_name"."meta_key" = "first_name" and "first_name"."post_id" = "posts"."ID"',
],
yield 'Without alias' => [
'my_meta',
null,
'select "posts".*, "my_meta"."meta_value" as "my_meta_value" from "posts" inner join "postmeta" as "my_meta" on "my_meta"."meta_key" = \'my_meta\' and "my_meta"."post_id" = "posts"."ID"',
];
yield 'With alias' => [
'first_name',
'my_custom_alias',
'select "posts".*, "first_name"."meta_value" as "my_custom_alias" from "posts" inner join "postmeta" as "first_name" on "first_name"."meta_key" = \'first_name\' and "first_name"."post_id" = "posts"."ID"',
];
}

Expand All @@ -96,32 +94,30 @@ public function testAddMetasToSelect(array $metas, string $expectedQuery): void
}

/**
* @return array
* @return \Generator
*/
public static function providerTestAddMetasToSelect(): array
public static function providerTestAddMetasToSelect(): \Generator
{
return [
'Without alias' => [
[
'firstname',
'lastname',
],
'select "posts".*, "firstname"."meta_value" as "firstname_value", "lastname"."meta_value" as "lastname_value" from "posts" inner join "postmeta" as "firstname" on "firstname"."meta_key" = "firstname" and "firstname"."post_id" = "posts"."ID" inner join "postmeta" as "lastname" on "lastname"."meta_key" = "lastname" and "lastname"."post_id" = "posts"."ID"',
yield 'Without alias' => [
[
'firstname',
'lastname',
],
'With alias' => [
[
'my_meta' => 'firstname',
'second_meta' => 'lastname',
],
'select "posts".*, "firstname"."meta_value" as "my_meta", "lastname"."meta_value" as "second_meta" from "posts" inner join "postmeta" as "firstname" on "firstname"."meta_key" = "firstname" and "firstname"."post_id" = "posts"."ID" inner join "postmeta" as "lastname" on "lastname"."meta_key" = "lastname" and "lastname"."post_id" = "posts"."ID"',
'select "posts".*, "firstname"."meta_value" as "firstname_value", "lastname"."meta_value" as "lastname_value" from "posts" inner join "postmeta" as "firstname" on "firstname"."meta_key" = \'firstname\' and "firstname"."post_id" = "posts"."ID" inner join "postmeta" as "lastname" on "lastname"."meta_key" = \'lastname\' and "lastname"."post_id" = "posts"."ID"',
];
yield 'With alias' => [
[
'my_meta' => 'firstname',
'second_meta' => 'lastname',
],
'On meta with alias on another one without alias' => [
[
'my_meta' => 'street_1',
'lastname',
],
'select "posts".*, "street_1"."meta_value" as "my_meta", "lastname"."meta_value" as "lastname_value" from "posts" inner join "postmeta" as "street_1" on "street_1"."meta_key" = "street_1" and "street_1"."post_id" = "posts"."ID" inner join "postmeta" as "lastname" on "lastname"."meta_key" = "lastname" and "lastname"."post_id" = "posts"."ID"',
'select "posts".*, "firstname"."meta_value" as "my_meta", "lastname"."meta_value" as "second_meta" from "posts" inner join "postmeta" as "firstname" on "firstname"."meta_key" = \'firstname\' and "firstname"."post_id" = "posts"."ID" inner join "postmeta" as "lastname" on "lastname"."meta_key" = \'lastname\' and "lastname"."post_id" = "posts"."ID"',
];
yield 'On meta with alias on another one without alias' => [
[
'my_meta' => 'street_1',
'lastname',
],
'select "posts".*, "street_1"."meta_value" as "my_meta", "lastname"."meta_value" as "lastname_value" from "posts" inner join "postmeta" as "street_1" on "street_1"."meta_key" = \'street_1\' and "street_1"."post_id" = "posts"."ID" inner join "postmeta" as "lastname" on "lastname"."meta_key" = \'lastname\' and "lastname"."post_id" = "posts"."ID"',
];
}

Expand All @@ -136,7 +132,7 @@ public function testJoinToMeta(): void
$this->builder->joinToMeta('my_meta');
$query = $this->builder->toSql();
$this->assertEquals(
'select "posts".* from "posts" inner join "postmeta" as "my_meta" on "my_meta"."meta_key" = "my_meta" and "my_meta"."post_id" = "posts"."ID"',
'select "posts".* from "posts" inner join "postmeta" as "my_meta" on "my_meta"."meta_key" = \'my_meta\' and "my_meta"."post_id" = "posts"."ID"',
$query
);
}
Expand All @@ -152,7 +148,7 @@ public function testAddMetaToFilter(): void
$query = $this->builder->toSql();

$this->assertEquals(
'select "posts".* from "posts" inner join "postmeta" as "firstname" on "firstname"."meta_key" = "firstname" and "firstname"."post_id" = "posts"."ID" where "firstname"."meta_value" = ?',
'select "posts".* from "posts" inner join "postmeta" as "firstname" on "firstname"."meta_key" = \'firstname\' and "firstname"."post_id" = "posts"."ID" where "firstname"."meta_value" = ?',
$query,
);

Expand Down