# Lesson 2.1 - Configure reference fields

Add reference fields to the Product and Landing page models and configure their type, direction, and cardinality.

In this lesson, you will add reference fields to the `Product` and `Landing page` models to connect them to other models in the schema. The reference type, direction, and cardinality configured here determine exactly what you will query later in the API Playground.

## Products and categories

Products need to be assignable to multiple categories, and categories need to display all their products. This requires a many-to-many, two-way reference. A two-way reference is required so you can query in both directions: from a product to its categories, and from a category to all its products.

[Video: Adding a reference field](https://eu-central-1-shared-euc1-02.graphassets.com/AvHQ3RDvFSousA8iwElOKz/cmnn9whb7jaef07w5i2wj3en0)

1. Open the **Product** model in the Schema editor and from the right sidebar, add a **Reference** field.
2. Configure the reference field with the following information:

    **Define relationship**

    | Field | Input |
    |---|---|
    | Reference type | Allow only one model to be referenced |
    | Model to reference | ProductCategory |
    | Reference directions | Two-way reference |
    | Allow multiple Products per ProductCategory | Select checkbox |
    | Allow multiple ProductCategories per Product | Select checkbox |
    | Relationship cardinality | The graphic displays that the relationship is of type many-to-many |

    **Configure reference**

    | Field | Input |
    |---|---|
    | Display name | Pre-configured. Leave as is. |
    | API ID | Pre-configured. Leave as is. |
    | Description | Select the categories that apply to your product |
    | Field visibility | Read / Write |

    **Configure reverse field**

    | Field | Input |
    |---|---|
    | Display name | Pre-configured. Leave as is. |
    | API ID | Pre-configured. Leave as is. |
    | Field visibility | Read / Write |

3. Click **Add** to save.

The reference field appears at the bottom of the model. Use the six-dot handle to drag it above the slug field.

[Video: Reorder reference field in schema](https://eu-central-1-shared-euc1-02.graphassets.com/AvHQ3RDvFSousA8iwElOKz/X7EG0VaxSjelihFLwc45)
 
**What this enables:** In lesson 7, you will be able to query `productCategory(where: { slug: "sportswear" }) { products { productName } }`. The query returns all products within that category. This is possible because of the two-way direction configured here.

## Landing page references

The `Landing page` model needs to display featured blog posts, product categories, and seller information. Each of these is a one-way reference. The `Landing page` queries into those models, but those models do not need to query back into `Landing pages`.

1. Open the **Landing page** model in the Schema editor and from the right sidebar under **Relation**, select **Reference**.

2. Configure the reference field for the `Blog post` model with the following information:

    **Define relationship**

    | Field | Input |
    |---|---|
    | Reference type | Allow only one model to be referenced |
    | Model to reference | BlogPost |
    | Reference directions | One-way reference |
    | Allow multiple BlogPosts per LandingPage | Select checkbox |

    **Configure reference**

    | Field | Input |
    |---|---|
    | Display name | Pre-configured. Leave as is. |
    | API ID | Pre-configured. Leave as is. |
    | Description | Featured item |
    | Field visibility | Read / Write |

3. Click **Add** to save.

4. Add another **Reference** field from the right sidebar. Configure the reference field for the `Product category` model with the following information:

    **Define relationship**

    | Field | Input |
    |---|---|
    | Reference type | Allow only one model to be referenced |
    | Model to reference | ProductCategory |
    | Reference directions | One-way reference |
    | Allow multiple ProductCategories per LandingPage | Select checkbox |

    **Configure reference**

    | Field | Input |
    |---|---|
    | Display name | Pre-configured. Leave as is. |
    | API ID | Pre-configured. Leave as is. |
    | Description | Browse our categories |
    | Field visibility | Read / Write |

5. Click **Add** to save.

6. Add another **Reference** field from the right sidebar. Configure the reference field for the `Seller information` model with the following information:

    **Define relationship**

    | Field | Input |
    |---|---|
    | Reference type | Allow only one model to be referenced |
    | Model to reference | SellerInformation |
    | Reference directions | One-way reference |
    | Relation cardinality | To one |

    **Configure reference**

    | Field | Input |
    |---|---|
    | Display name | Pre-configured. Leave as is. |
    | API ID | Pre-configured. Leave as is. |
    | Description | Business information |
    | Field visibility | Read / Write |

7. Click **Add** to save.

Your Landing page model should now look like this:

![Your Landing page model so far](https://hygraph.com/images/docs/getting-started/landing-page-model-with-references.png)

**Why one-way for Landing page references, but two-way for Products and categories?**
A Blog post, Product category, or Seller information entry has no use case for querying which landing pages reference it. The two-way reference on Products and categories exists because the project needs to navigate from both sides. Where that bidirectional query isn't needed, a one-way reference keeps the schema clean.

## What's next

[Lesson 3 - Enumerations](https://hygraph.com/docs/getting-started/tutorial/tutorial-enumerations-overview)

Or, go to the [Tutorial overview](https://hygraph.com/docs/getting-started/tutorial/tutorial-overview) for the full lesson list.
