Data modeling

Data modeling is the process of configuring a shared set of resource types needed to store the data (resources) that your project needs to meet its specific requirements.

For example, if your project were a restaurant website, it may need pages for:

  • A homepage
  • Menu
  • Wine list
  • A staff listing
  • Staff member bios
  • Catering details
  • The history of the restaurant

Each of these pages would be a project resource, but not every resource needs a distinct resource type. Resource types can be reused as many times as needed.

Defining resource types

Continuing with the restaurant example, let's define some resource types. The menu and wine list pages may share a similar design and data structure. They both need a title and a list of items, each with a label, description and price. Therefore, they can reuse the same resource type.

The catering and history pages may all share the same design and structure too. They both need an image and long text area, so they can reuse a resource type too.

However, the homepage, staff listing, and staff bio pages are unique. The homepage may need a section for contact details, a link to book a reservation off-site, and a section for the restaurant's opening hours. The staff listing needs a short blurb and a listing of teasers that links to each staff member's bio page. Finally, the staff bio page needs a required image, a short text area, a job title, and a quote.

Therefore, you may choose to create five resource types named:

  1. Menu
  2. Basic page
  3. Home page
  4. Staff listing
  5. Staff bio

Why bother?

It is possible, but not recommended, to create and use fewer, more generic resource types. However, breaking resources down into their component parts will make your project's front end easier to build, style, and maintain. Without appropriate structure, you'll find that your front end will become more difficult to style because you'll need to add exceptions and handle more edge cases.

A good data model should also be easy for the project's editors to understand and update. Resource type names are used in the editor interface, so be sure to give your resource types names that will make sense to others and avoid developer-focused names. For example, the example above uses the name "Menu" instead of "Purchasable collection".

Creating a resource type

To create a new resource type in your project's management interface,

  1. Follow the Structure link in the primary menu
  2. Follow the Resource types link on the subsequent page
  3. Click the Add resource type button
  4. Fill in the resource type form
  5. Click Save and manage fields

The name you enter will be used to generate a machine name. The machine name can't be changed later, but everything else is editable. Machine names are only used in front end application code.

Every resource requires a title. However, you can override its label. For example, you may want to change "Title" to "Full name" for a staff bio resource type. Even if you don't display the title in your front end, it will be used as an administrative label in your project's management UI.

If you choose, you can also prevent a resource from being published automatically. Resources that aren't published can only be viewed by logged-in users with access to your project. This mechanism is useful for draft content.