-
-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Autocomplete] Fix handling of associated properties in DQL joins
- Loading branch information
1 parent
89c7fa9
commit cc87e60
Showing
9 changed files
with
411 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\Autocomplete\Tests\Fixtures\Entity; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity()] | ||
class CategoryTag | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column()] | ||
private ?int $id = null; | ||
|
||
#[ORM\Column()] | ||
private ?string $name = null; | ||
|
||
#[ORM\ManyToMany(targetEntity: Category::class, inversedBy: 'tags')] | ||
#[ORM\JoinTable(name: 'category_tag')] | ||
private Collection $categories; | ||
|
||
public function __construct() | ||
{ | ||
$this->categories = new ArrayCollection(); | ||
} | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(string $name): self | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return Collection<int, Category> | ||
*/ | ||
public function getCategories(): Collection | ||
{ | ||
return $this->categories; | ||
} | ||
|
||
public function addCategory(Category $category): self | ||
{ | ||
if (!$this->categories->contains($category)) { | ||
$this->categories[] = $category; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function removeCategory(Category $category): self | ||
{ | ||
$this->categories->removeElement($category); | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\Autocomplete\Tests\Fixtures\Entity; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\Common\Collections\Collection; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity()] | ||
class ProductTag | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column()] | ||
private ?int $id = null; | ||
|
||
#[ORM\Column()] | ||
private ?string $name = null; | ||
|
||
#[ORM\ManyToMany(targetEntity: Product::class, inversedBy: 'tags')] | ||
#[ORM\JoinTable(name: 'product_tag')] | ||
private Collection $products; | ||
|
||
public function __construct() | ||
{ | ||
$this->products = new ArrayCollection(); | ||
} | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getName(): ?string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName(string $name): self | ||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return Collection<int, Product> | ||
*/ | ||
public function getProducts(): Collection | ||
{ | ||
return $this->products; | ||
} | ||
|
||
public function addProduct(Product $product): self | ||
{ | ||
if (!$this->products->contains($product)) { | ||
$this->products[] = $product; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function removeProduct(Product $product): self | ||
{ | ||
$this->products->removeElement($product); | ||
|
||
return $this; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/Autocomplete/tests/Fixtures/Factory/CategoryTagFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\Autocomplete\Tests\Fixtures\Factory; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
use Symfony\UX\Autocomplete\Tests\Fixtures\Entity\CategoryTag; | ||
use Zenstruck\Foundry\ModelFactory; | ||
use Zenstruck\Foundry\Proxy; | ||
use Zenstruck\Foundry\RepositoryProxy; | ||
|
||
/** | ||
* @extends ModelFactory<CategoryTag> | ||
* | ||
* @method static CategoryTag|Proxy createOne(array $attributes = []) | ||
* @method static CategoryTag[]|Proxy[] createMany(int $number, array|callable $attributes = []) | ||
* @method static CategoryTag|Proxy find(object|array|mixed $criteria) | ||
* @method static CategoryTag|Proxy findOrCreate(array $attributes) | ||
* @method static CategoryTag|Proxy first(string $sortedField = 'id') | ||
* @method static CategoryTag|Proxy last(string $sortedField = 'id') | ||
* @method static CategoryTag|Proxy random(array $attributes = []) | ||
* @method static CategoryTag|Proxy randomOrCreate(array $attributes = []) | ||
* @method static CategoryTag[]|Proxy[] all() | ||
* @method static CategoryTag[]|Proxy[] findBy(array $attributes) | ||
* @method static CategoryTag[]|Proxy[] randomSet(int $number, array $attributes = []) | ||
* @method static CategoryTag[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) | ||
* @method static EntityRepository|RepositoryProxy repository() | ||
* @method CategoryTag|Proxy create(array|callable $attributes = []) | ||
*/ | ||
final class CategoryTagFactory extends ModelFactory | ||
{ | ||
protected function getDefaults(): array | ||
{ | ||
return [ | ||
'name' => self::faker()->word(), | ||
]; | ||
} | ||
|
||
protected function initialize(): self | ||
{ | ||
return $this; | ||
} | ||
|
||
protected static function getClass(): string | ||
{ | ||
return CategoryTag::class; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/Autocomplete/tests/Fixtures/Factory/ProductTagFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\UX\Autocomplete\Tests\Fixtures\Factory; | ||
|
||
use Doctrine\ORM\EntityRepository; | ||
use Symfony\UX\Autocomplete\Tests\Fixtures\Entity\ProductTag; | ||
use Zenstruck\Foundry\ModelFactory; | ||
use Zenstruck\Foundry\Proxy; | ||
use Zenstruck\Foundry\RepositoryProxy; | ||
|
||
/** | ||
* @extends ModelFactory<ProductTag> | ||
* | ||
* @method static ProductTag|Proxy createOne(array $attributes = []) | ||
* @method static ProductTag[]|Proxy[] createMany(int $number, array|callable $attributes = []) | ||
* @method static ProductTag|Proxy find(object|array|mixed $criteria) | ||
* @method static ProductTag|Proxy findOrCreate(array $attributes) | ||
* @method static ProductTag|Proxy first(string $sortedField = 'id') | ||
* @method static ProductTag|Proxy last(string $sortedField = 'id') | ||
* @method static ProductTag|Proxy random(array $attributes = []) | ||
* @method static ProductTag|Proxy randomOrCreate(array $attributes = []) | ||
* @method static ProductTag[]|Proxy[] all() | ||
* @method static ProductTag[]|Proxy[] findBy(array $attributes) | ||
* @method static ProductTag[]|Proxy[] randomSet(int $number, array $attributes = []) | ||
* @method static ProductTag[]|Proxy[] randomRange(int $min, int $max, array $attributes = []) | ||
* @method static EntityRepository|RepositoryProxy repository() | ||
* @method ProductTag|Proxy create(array|callable $attributes = []) | ||
*/ | ||
final class ProductTagFactory extends ModelFactory | ||
{ | ||
protected function getDefaults(): array | ||
{ | ||
return [ | ||
'name' => self::faker()->word(), | ||
]; | ||
} | ||
|
||
protected function initialize(): self | ||
{ | ||
return $this; | ||
} | ||
|
||
protected static function getClass(): string | ||
{ | ||
return ProductTag::class; | ||
} | ||
} |
Oops, something went wrong.