如何解决关联在数据库中,但无法通过DAL检索将检索空的关联数组
我正在关注高级开发者教程(Automatically bind the challenge to a button)。
目前我处于第7步,根据本教程,我到目前为止所做的工作应该可以正常工作。
但事实并非如此。
解决方法
您必须将关联添加到条件中。
$criteria->addAssociation("name_of_association")
没有它,关联就为空。
好吧,事实证明,我偶然打开了两个参数。当我正确设置它们时,它应该可以正常工作。
<?php declare(strict_types=1);
namespace Swag\BundleExample\Core\Content\Product;
use Shopware\Core\Content\Product\ProductDefinition;
use Shopware\Core\Framework\DataAbstractionLayer\EntityExtension;
use Shopware\Core\Framework\DataAbstractionLayer\Field\Flag\Inherited;
use Shopware\Core\Framework\DataAbstractionLayer\Field\ManyToManyAssociationField;
use Shopware\Core\Framework\DataAbstractionLayer\FieldCollection;
use Swag\BundleExample\Core\Content\Bundle\Aggregate\BundleProduct\BundleProductDefinition;
use Swag\BundleExample\Core\Content\Bundle\BundleDefinition;
class ProductExtension extends EntityExtension
{
public function extendFields(FieldCollection $collection): void
{
$collection->add(
(new ManyToManyAssociationField(
'bundles',BundleDefinition::class,BundleProductDefinition::class,'product_id','bundle_id'
))->addFlags(new Inherited())
);
}
public function getDefinitionClass(): string
{
return ProductDefinition::class;
}
}
我说的是'product_id'和'bundle_id'。就我而言,我将“ product_id”作为最后一个参数。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。