当我尝试发布到Shopware 6数据库表时,我得到一个400
状态响应,其中包含额外的详细信息此值太长。小于等于255个字符。
.我的数据库表是clu_product_text我要更新的表列是description并接受长文本。400年status错误消息为">此值太长。小于等于255个字符。">
下面是我的代码:
const { Component} = Shopware;
const { Criteria } = Shopware.Data;
Component.register('clu-administration-page', {
template,
inject: [
'repositoryFactory',
'syncService'
],
metaInfo() {
return {
title: this.$createTitle()
};
},
data: function () {
return {
description: "For writers, a random sentence can help them get their creative juices flowing. Since the topic of the sentence is completely unknown, it forces the writer to be creative when the sentence appears. There are a number of different ways a writer can use the random sentence for creativity. The most common way to use the sentence is to begin a story. Another option is to include it somewhere in the story. A much more difficult challenge is to use it to end a story. In any of these cases, it forces the writer to think creatively since they have no idea what sentence will appear from the tool.",
id: "34eh9037492h2781",
isLoading: true
}
},
computed: {
cluProductTextRepository() {
return this.repositoryFactory.create('clu_product_text');
},
},
methods: {
updateCluProductText(){
this.cluProductTextRepository
.get(this.id, Shopware.Context.api)
.then((update) => {
update.description = this.description;
this.cluProductTextRepository.save(update, Shopware.Context.api);
});
}
},
created() {
this.updateCluProductText();
}
});
自定义实体定义上的StringField
有第三个参数maxLength
,默认设置为255。对于较长的文本,您应该使用LongTextField
。
所以我假设你的实体定义看起来像这样:
public function defineFields(): FieldCollection
{
return new FieldCollection([
... your other fields
new StringField('clu_product_text', 'cluProductText'),
]);
}
你应该使用LongTextField
:
public function defineFields(): FieldCollection
{
return new FieldCollection([
... your other fields
new LongTextField('clu_product_text', 'cluProductText'),
]);
}