This project is read-only.

Creating 1-n and n-n relations

Topics: General, Writing modules
Jul 14, 2011 at 5:16 AM

I am reading through and am stuck on the Migration part of the 1-N at the moment.

I installed the DateTimeField Module and created a Migration as follows:

using System.Data;
using Contrib.DateTimeField.Fields;
using Orchard.ContentManagement.MetaData;
using Orchard.Data.Migration;

namespace beanpole.Orchard.CCM
    public class Migrations : DataMigrationImpl
        public int Create()
                table => table
                    .Column("Name", DbType.String)
                    .Column("EndedAt", DbType.DateTime)

                cfg => cfg

                cfg => cfg
                        field => field

            return 1;

Then I enabled my module which I have configured to also enable the Contrib.DateTimeField.

I can open the page http://localhost:30320/Admin/ContentTypes/Edit/Appointment at this stage of the tutorial but I cannot see any fields, only a couple of Parts.

Should I be able to see the fields at this stage or will they appear later in the tutorial.

Jul 14, 2011 at 5:22 AM

If your migration ran, you should see the field, I think.

Jul 14, 2011 at 7:11 AM

The Migration ran and I see the Id, Name and EndedAt fields. I thought the .WithField at the end would add a StartedAt field but it didn't. I have to add StartedAt into the CreateTable statement to see it.

I am trying to get the StartedAt field to be a Contrib.DateTimeField type Field. How do I do that?

Jul 14, 2011 at 7:15 AM

Fields don't get stored as columns. They get stored as xml in a single column of the part.

Jul 14, 2011 at 7:35 AM
Edited Jul 14, 2011 at 7:37 AM

Can I use the functionality of the Contrib.DateTimeField with all the jquery fun on top of the DateTime columns and not use a Field then? Or do I have to rewrite that into my View?

Jul 14, 2011 at 7:43 AM

No, fields are for... fields. You could probably reuse some of the code, but not directly. There are plenty of examples of date properties though.

Jul 14, 2011 at 8:15 AM

Storing the data in xml like that for important information is a bit scary. If I wanted to write some reports or something then that adds another layer of processing that I need to do before I can use the data for filtering or indexing or just in a good old fashioned where clause. Am I making too big a deal of it if I say I prefer to see the data stored in a normal table.column? How hard would it be to make a field store its data in a table column instead? What would be involved?

Jul 14, 2011 at 8:17 AM

If it's important information, write a part with a real property. Fields are for "unimportant" information.