Altering a ContentPartRecord

Topics: Customizing Orchard, Writing modules
Nov 19, 2012 at 12:07 PM
Edited Nov 19, 2012 at 12:08 PM

Hi

I have created a ContentPartRecord with one property, and it is working as expected.

I am now in the process of upgrading the module, and I need to add a second property to the ContentPartRecord. I have added the new property to the Record and the Part classes, and have updated the cshtml file to display a textbox to allow the user to update this value. I have also updated my migrations file to add a column to the table to store the new property.

However- when I go to save my record, my new property is not persisted but the original one is. More specifically, there appears to be two issues occurring here:

  1. In the Editor post method in the driver, the new property on the part is always passed as NULL.
  2. If I hard-code the new property to an arbitrary value immediately before I call IUpdateModel.TryUpdateModel, that method appears to ignore the new property and it is passed back as NULL

I'm not too sure what could be the cause of this, can anyone shed some light here?

One line of thought is that when the first property was created on the part, the migration looked like this: 

 

public int UpdateFrom1()
        {
            SchemaBuilder.CreateTable("ScheduledGamesContainerRecord", table =>
                table.ContentPartRecord()
                    .Column("NumberOfGamesToShow", col => col.WithDefault(10)));

            return 2;
        }

 

I have added the new property like this:

 

public int UpdateFrom5()
        {
            SchemaBuilder.AlterTable("ScheduledGamesContainerRecord", table =>
                table.AddColumn<string>("Skin"));

            return 6;
        }

 

Do I need to call ContentPartRecord again on the table? I cant see a way to do this on AlterTable. Any help would be greatly appreciated.

Nov 19, 2012 at 1:05 PM

OK, so I have an update on this.

Without changing any of the files, I deleted my App_Data folder and re-installed Orchard. Now, the second property that I have added appears to be working.

 

The question now is- why did this work from a clean install and not from an upgrade? Am I doing something wrong, or is this a bug? The table that the column got added to already had some values in- do I need to run something on those records?

Nov 19, 2012 at 3:40 PM

I get this issue too. The only way I can get it to work is to trash the database and reconfigure :(  I've tried adding the value directly into the SQL table, to see what happens, but it won't use that value.

Coordinator
Nov 23, 2012 at 3:29 AM

Definitely not normal as that is the point of migrations, but is it possible that your migration had an error that you didn't notice? Did you check if the column had been created in the DB? Did the migration number increase in the DB? Did you try deleting your mappings.bin file?

Nov 23, 2012 at 9:55 AM

Hi Bertrand

Thanks for your reply. The column does get created in the database, and the migrations number also increases as expected. This leads me to believe that the migration file is fine.

I just tried deleting my mappings.bin file, and that seems to have done the trick. Have you got any idea why the new property is not persisted until the mappings.bin file gets deleted? How can we force this file to be updated without having to go in and manually remove it every time we make a change to a module?

 

 

Thanks

Coordinator
Nov 26, 2012 at 10:13 PM

I don't know. If you have a repro, please file a bug.

Nov 27, 2012 at 11:46 AM

Logged an issue with repro. Issue number 19306