带有自定义实体的管理面具,并带

发布于 2025-02-13 02:16:16 字数 3750 浏览 0 评论 0原文

我有一个shotware6管理员扩展程序,其中一些自定义实体存储和加载。该自定义实体具有对另一个自定义实体的多曼尼亚汇编。在我的面具中,我使用实体多选择组件进行选择。

const category = this.categoryRepository.create();
            category.categoryId = this.newCategory;
            category.weight = this.newWeight;
            category.certificates = this.certificateCollection;
            this.categoryRepository.save(category).then(() => {
                this.isLoading = false;
                this.isSaveSuccessful = true;
                this.getList();
            }).catch((exception) => {
                this.isLoading = false;
                this.createNotificationError({
                    message: this.$tc(
                        'global.notification.notificationSaveErrorMessageRequiredFieldsInvalid'
                    )
                });
                throw exception;
            });
<sw-entity-multi-select
                    :label-property="labelPropertyCertificate"
                    :criteria="certificateCriteria"
                    entity-name="certificate"
                    :entity-collection="certificateCollection"
                    @change="changeCertificates"
            />

发送保存请求时,我的证书选择的内容与属性ID一起发送和JS对象。为了创建正确的实体,我添加了一些实体创建过程,并为类别的集合构建了自己的实体集合。

像这样

const category = this.categoryRepository.create();
            category.categoryId = this.newCategory;
            category.weight = this.newWeight;
            category.certificates = new EntityCollection(
                this.categoryCertificateRepository.route,
                this.categoryCertificateRepository.entityName,
                Context.api,
            );
            this.certificates.forEach(function(item){
                const categoryCertificate = me.categoryCertificateRepository.create();
                categoryCertificate.categoryId = category.id;
                categoryCertificate.certificateId = item.id;
                category.certificates.add(categoryCertificate);
            });


            console.log(category);
            this.categoryRepository.save(category).then(() => {
                this.isLoading = false;
                this.isSaveSuccessful = true;
                this.getList();
            }).catch((exception) => {
                this.isLoading = false;
                this.createNotificationError({
                    message: this.$tc(
                        'global.notification.notificationSaveErrorMessageRequiredFieldsInvalid'
                    )
                });
                throw exception;
            });

console.log显示了这一点,这是正确的

类别:“ 77B959CF66DE4C1590C7F9B7DA3982F3” 证书:R(1) 0:代理 [[处理程序]]:对象 [[目标]]:对象 类别:“ AA26DAAB83B04CC6AF9A525E7EC1CE16” 证书ID:“ 8C32FB76000844BCB4D850831FE2F6C1” 扩展:{} _isnew:是的 [[原型]]:对象 [[Isrevoked]]:false ...

请求有效载荷显示了这一点,这是不正确的。

{id:“ B96C923DCEE941C7A05C0CB4F98DE4D9”,categoryId:“ 251448B91BC742DE85643F5FCCD89051” 类别:“ 251448B91BC742DE85643F5FCCD89051” 证书:[{ID:“ 10FB19BCCDB0419CA5F4B7ABE6561DB2”}]] ID:“ B96C923DCEE941C7A05C0CB4F98DE4D9” 重量:0

我的类别在哪里&amp;证书属性属性消失了吗?该类别是否会剥离它们?

编辑解决方案

to dneustadt

this.certificates.forEach(function(item){
                const categoryCertificate = me.careHintCategoryCertificateRepository.create();
                categoryCertificate.id = item.id;
                category.certificates.add(categoryCertificate);
            });

这可以工作!

I have an shopware6 admin extension where some custom entity is stored and loaded. This custom entity has a ManyToManyAssociation to another custom entity. In my mask I use a entity multi select component for the selection.

const category = this.categoryRepository.create();
            category.categoryId = this.newCategory;
            category.weight = this.newWeight;
            category.certificates = this.certificateCollection;
            this.categoryRepository.save(category).then(() => {
                this.isLoading = false;
                this.isSaveSuccessful = true;
                this.getList();
            }).catch((exception) => {
                this.isLoading = false;
                this.createNotificationError({
                    message: this.$tc(
                        'global.notification.notificationSaveErrorMessageRequiredFieldsInvalid'
                    )
                });
                throw exception;
            });
<sw-entity-multi-select
                    :label-property="labelPropertyCertificate"
                    :criteria="certificateCriteria"
                    entity-name="certificate"
                    :entity-collection="certificateCollection"
                    @change="changeCertificates"
            />

When sending the save request the content of my certificate selection is send with and js object with the property id. To create the correct entity I added some Entity creation process and build my own entity collection for the categoryCertificate collection.

Like this

const category = this.categoryRepository.create();
            category.categoryId = this.newCategory;
            category.weight = this.newWeight;
            category.certificates = new EntityCollection(
                this.categoryCertificateRepository.route,
                this.categoryCertificateRepository.entityName,
                Context.api,
            );
            this.certificates.forEach(function(item){
                const categoryCertificate = me.categoryCertificateRepository.create();
                categoryCertificate.categoryId = category.id;
                categoryCertificate.certificateId = item.id;
                category.certificates.add(categoryCertificate);
            });


            console.log(category);
            this.categoryRepository.save(category).then(() => {
                this.isLoading = false;
                this.isSaveSuccessful = true;
                this.getList();
            }).catch((exception) => {
                this.isLoading = false;
                this.createNotificationError({
                    message: this.$tc(
                        'global.notification.notificationSaveErrorMessageRequiredFieldsInvalid'
                    )
                });
                throw exception;
            });

The console.log shows this, which would be correct

categoryId: "77b959cf66de4c1590c7f9b7da3982f3"
certificates: r(1)
0: Proxy
[[Handler]]: Object
[[Target]]: Object
categoryId: "aa26daab83b04cc6af9a525e7ec1ce16"
certificateId: "8c32fb76000844bcb4d850831fe2f6c1"
extensions: {}
_isNew: true
[[Prototype]]: Object
[[IsRevoked]]: false
...

The request payload shows this, which is not correct.

{id: "b96c923dcee941c7a05c0cb4f98de4d9", categoryId: "251448b91bc742de85643f5fccd89051", weight: 0,…}
categoryId: "251448b91bc742de85643f5fccd89051"
certificates: [{id: "10fb19bccdb0419ca5f4b7abe6561db2"}]
id: "b96c923dcee941c7a05c0cb4f98de4d9"
weight: 0

where are my categoryId & certificateId properties gone? Does the categoryRepository strip them out?

Edit solution

Thx to dneustadt

this.certificates.forEach(function(item){
                const categoryCertificate = me.careHintCategoryCertificateRepository.create();
                categoryCertificate.id = item.id;
                category.certificates.add(categoryCertificate);
            });

this works!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哆啦不做梦 2025-02-20 02:16:16

通过使用ManyTomanyAssociationField动态解析了映射表列的值。由于这些列属于映射定义,而不属于您的实际categoryCertificate实体,因此它们被剥离了。当您使用相应的ManyTomanyAssociationField属性来分配两侧的数据时,您无需提供这些ID。

By using a ManyToManyAssociationField the values for the columns of the mapping table are resolved dynamically. Since these columns belong to the mapping definition, not to your actual CategoryCertificate entity, they get stripped. You don't need to provide these IDs when you use the respective ManyToManyAssociationField property to assign data from either side.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文