Comments (9)
Thx for reporting the issue, could you share us your supplier repository?
from syliusresourcebundle.
Hello @loic425 , Thanks for your reply.
This is how the SupplyRepository looks
`
* * @method Supplier|null find($id, $lockMode = null, $lockVersion = null) * @method Supplier|null findOneBy(array $criteria, array $orderBy = null) * @method Supplier[] findAll() * @method Supplier[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) */ class SupplierRepository extends ServiceEntityRepository implements RepositoryInterface { use ResourceRepositoryTrait; public function __construct(ManagerRegistry $registry) { parent::__construct($registry, Supplier::class); } // /** // * @return Supplier[] Returns an array of Supplier objects // */ // public function findByExampleField($value): array // { // return $this->createQueryBuilder('s') // ->andWhere('s.exampleField = :val') // ->setParameter('val', $value) // ->orderBy('s.id', 'ASC') // ->setMaxResults(10) // ->getQuery() // ->getResult() // ; // } // public function findOneBySomeField($value): ?Supplier // { // return $this->createQueryBuilder('s') // ->andWhere('s.exampleField = :val') // ->setParameter('val', $value) // ->getQuery() // ->getOneOrNullResult() // ; // } } `from syliusresourcebundle.
namespace App\Repository\Inventory;
use App\Entity\Inventory\Supplier;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\ResourceRepositoryTrait;
use Sylius\Component\Resource\Repository\RepositoryInterface;
/**
* @extends ServiceEntityRepository<Supplier>
*
* @method Supplier|null find($id, $lockMode = null, $lockVersion = null)
* @method Supplier|null findOneBy(array $criteria, array $orderBy = null)
* @method Supplier[] findAll()
* @method Supplier[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class SupplierRepository extends ServiceEntityRepository implements RepositoryInterface
{
use ResourceRepositoryTrait;
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Supplier::class);
}
// /**
// * @return Supplier[] Returns an array of Supplier objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('s.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
// public function findOneBySomeField($value): ?Supplier
// {
// return $this->createQueryBuilder('s')
// ->andWhere('s.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
}
from syliusresourcebundle.
@nkamuo
I did'nt reproduce your issue in an empty symfony 6.3 project.
Do you have a routing with this entity?
For information:
# config/packages/sylius_resource.yaml
sylius_resource:
mapping:
paths:
- '%kernel.project_dir%/src/Entity'
resources:
# You can remove this configuration, this is auto-registered now.
#app.supplier:
# driver: doctrine/orm
# classes:
# model: App\Entity\Inventory\Supplier
#[Resource(alias: 'app.supplier')]
This alias is the default value.
from syliusresourcebundle.
Yes - I had the configuration and also specified the Resource entity explicitly.
# config/packages/sylius_resource.yaml
sylius_resource:
mapping:
paths:
- "%kernel.project_dir%/src/Entity"
resources:
app.supplier:
driver: doctrine/orm
classes:
model: App\Entity\Inventory\Supplier
app.purchase_order:
driver: doctrine/orm
classes:
model: App\Entity\Inventory\PurchaseOrder
form: App\Form\Inventory\PurchaseOrderType
However, I was able to solve the issue by switching my entity metadata from PHP8 attributes to Doctrine annotations.
Now, everything works so well since switching to annotations.
Do you have a workaround for this.
Thanks for your help so far.
This is how my Supplier class looks now.
namespace App\Entity\Inventory;
use App\Repository\Inventory\SupplierRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Resource\Metadata\Resource;
use Sylius\Component\Resource\Model\ResourceInterface;// as ResourceMetadata;
// #[Resource(alias: 'app.supplier')]
/**
* @ORM\Entity(repositoryClass=SupplierRepository::class)
* @ORM\Table(name="app_inventory_supplier")
*/
class Supplier implements ResourceInterface
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column
*/
private ?int $id = null;
/**
* @ORM\Column(length=32, unique=true)
*/
private ?string $code = null;
/**
* @ORM\Column(length=64)
*/
private ?string $name = null;
/**
* @ORM\Column(type=Types::TEXT,length=255, nullable=true)
*/
// #[ORM\Column(type: Types::TEXT, length: 255, nullable: true)]
private ?string $description = null;
/**
* @ORM\Column(type="boolean")
*/
private ?bool $enabled = null;
// #[ORM\OneToMany(mappedBy: 'supplier', targetEntity: PurchaseOrder::class)]
/**
* @ORM\OneToMany(targetEntity=PurchaseOrder::class, mappedBy="supplier")
*/
private Collection $purchaseOrders;
public function __construct()
{
$this->purchaseOrders = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): static
{
$this->code = $code;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function isEnabled(): ?bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): static
{
$this->enabled = $enabled;
return $this;
}
/**
* @return Collection<int, PurchaseOrder>
*/
public function getPurchaseOrders(): Collection
{
return $this->purchaseOrders;
}
public function addPurchaseOrder(PurchaseOrder $purchaseOrder): static
{
if (!$this->purchaseOrders->contains($purchaseOrder)) {
$this->purchaseOrders->add($purchaseOrder);
$purchaseOrder->setSupplier($this);
}
return $this;
}
public function removePurchaseOrder(PurchaseOrder $purchaseOrder): static
{
if ($this->purchaseOrders->removeElement($purchaseOrder)) {
// set the owning side to null (unless already changed)
if ($purchaseOrder->getSupplier() === $this) {
$purchaseOrder->setSupplier(null);
}
}
return $this;
}
}
from syliusresourcebundle.
Have you configured Doctrine to work with attributes?
# config/packages/doctrine.yaml
doctrine:
orm:
auto_generate_proxy_classes: '%kernel.debug%'
entity_managers:
default:
auto_mapping: true
mappings:
App:
is_bundle: false
type: attribute
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
from syliusresourcebundle.
@nkamuo Is that fixed for you?
from syliusresourcebundle.
I was able to fix it by changing the type: attribute
to type: annotation
.
I think the default doctrine config on sylius does not specify the metadata type [attribute or annotation] but defaults to annotation.
So when I switched to attribute as you suggested, other Sylius entities[Product, Order, ProductVariant ...] become invisible to doctrine. I had to rewrite the generated entities to annotation and everything works so well now.
from syliusresourcebundle.
Thanks @loic425 for your support - You pointed me in the right direction.
from syliusresourcebundle.
Related Issues (20)
- Add flash from event
- Resource identifier
- Custom resource name
- Custom resource plural name
- Custom operation path
- Custom operation short name
- Operation route path factory improved
- Unable to access "form.factory" service from Symfony 6 in ResourceController
- Symfony 6.3 deprecation doctrine subscribers HOT 1
- Call to undefined method createBuilder HOT 3
- [Bug] The HttpFoundationRequestHandler class is not compatible with some form usages
- Replace scalarNode with enumNode usage for "only", "except" routing configuration
- Update rector.php config to php8.0 and constructor property promotion in particular
- Replace usage of "Gedmo\Sluggable\Util\Urlizer" with "Behat\Transliterator\Transliterator", since it's already used internally
- Complete code refactor after "RouteFactory" was introduced
- Configure phparkitect/arkitect rules for design considerations
- SyliusCrudRoutes: lost routes after last update
- Cleanup aliases for `sylius.resource_metadata_collection.factory.attributes` service
- `TargetEntitiesResolver` incorrectly filters out interfaces when it encounters the model twice
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from syliusresourcebundle.