Search⌘ K
AI Features

The Placement Model

Explore how to create the Placement model that links orders and products with a many-to-many association. Understand generating the model, running migrations, and updating associations to effectively manage order placements in a Rails API.

We need to set up the association between the order and the product with a has-many-to-many association. As each product can be placed in multiple orders and each order can have multiple products, we need a model that will join the two objects and map the appropriate association.

Generate the Placement model

Let’s generate the Placement model using this command in the terminal below:

$ rails generate model
...