Orchard CMS - 如何使用数据库管理自定义模块小部件的新字段? [英] Orchard CMS - How to manage new fields for custom module widget with database?

查看:39
本文介绍了Orchard CMS - 如何使用数据库管理自定义模块小部件的新字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用一个自定义模块,该模块具有一个小部件,其中一些字段存储在数据库中.我向小部件添加了一个新的非必填字段,并且未添加数据库中的相应字段.处理此类变化的最佳方法是什么?

I've been working with a custom module that has a widget with some fields stored in the DB. I added a new non-required field to the widget and a corresponding field in the database is not being added. What's the best way to handle this type of change?

我可以在开发数据库中手动添加一个字段来匹配它,但这对于 50 个奇怪的生产租户站点来说是不现实的.

I can manually add a field in the dev database to match it, but this is unrealistic for 50 some odd production tenant sites.

推荐答案

为了稍微扩展@Bertand 的回答,添加字段(布尔字段、文本字段、媒体选择器字段等)时不需要创建数据库列) 到内容部分,因为用于存储字段的数据库结构已经在数据库中.

To expand on @Bertand's answer a little, you don’t need to create database columns when you add fields (Boolean Field, Text Field, Media Picker Field etc) to content parts because the database structure for storing fields is already in place in the database.

字段存储为针对内容部分的序列化 XML.我的所有记录都存储在 Orchard_Framework_ContentItemVersionRecord 表中(有一个类似的表 Orchard_Framework_ContentItemRecord,但似乎没有使用.

Fields are stored as serialized XML against the content part. All of my records are stored in the Orchard_Framework_ContentItemVersionRecord table (there’s a similar table Orchard_Framework_ContentItemRecord, but that doesn’t appear to be used.

XML 本质上是以下格式:

The XML is essentially of the format:

<Data>
    <SomePart>
        <SomeFieldName SomeFieldProperty="value"
                       SomeOtherProperty="value">FieldValue</SomeFieldName>
    </SomePart>
    <SomeOtherPart>
        <SomeOtherFieldName>FieldValue</SomeOtherFieldName>
    </SomeOtherPart>
</Data>

因此,例如,您可能有这样的事情:

So, for example you might have something like this:

<Data>
    <PicturePart>
        <picture AlternateText="" Class="" Style="" Alignment="" Width="1219"
                 Height="709">~/Media/Default/images/greatPicture.jpg</picture>
    </PicturePart>
    <PictureType>
        <ExtraDescription>It’s a great picture!</ExtraDescription>
    </Pictureype>
</Data>

Orchard 使用 Settings_XXXRecord 表中的信息来确定从数据库反序列化字段时的字段类型.

Orchard uses the information from the Settings_XXXRecord tables to determine the types of the fields when it’s deserializing them back from the database.

这就是为什么,正如 Bertand 在此处所说,字段更容易创建,但更难查询.

All of this is why, as Bertand says here, fields are easier to create, but harder to query.

查看您发布的解决方案,看起来您正在添加自定义列,而不是 Orchard Fields.如果这您正在尝试执行的操作,那么您似乎应该使用 AddColumn 在模块的数据迁移中执行某些操作,如此处.这看起来像:

Looking at the solution you've posted, it looks like you're adding custom columns, rather than Orchard Fields. If this is what you're trying to do, then it seems like something you should be doing in a datamigration for your module by using AddColumn, as described here. This would look something like:

public int UpdateFrom1() {
    SchemaBuilder.AlterTable("TABLE_NAME", table => table
            .AddColumn<int>("mynewcolumn")
            .AddColumn<string>("mynewcolumn2")
       );
    return 2;
}

这篇关于Orchard CMS - 如何使用数据库管理自定义模块小部件的新字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆