One-to-one, many-to-one or many-to-many relationship management in the new cockpit v2

I have a question about how to use the tool, how I could implement fields with a one-to-one or many-to-many relationship taking into account that the database structure that is managed is non-relational, how I could create a customer model and be able to relate a customer model to it. Vehicle created from another model so that both are linked and thus be able to make queries to bring all the data of the client’s vehicle?

To handle relationships in Cockpit, you can create “content link” fields.

Suppose that we have three models, Article , Comment and Book.

One to One and One to Many

For a one-to-one or one-to-many relationship, you can link a single article with multiple comments. To do this, create a field called “comments” in the Article model with a field type of “Content Link.” In the Options tab, select the model you want to link by using the Link selector. By default, this creates a one-to-one relationship, but you can enable “Allow Multiple Values” under the General tab to make it a one-to-many relationship.

When creating a new article, you’ll see as below screenshot, you can add multiple comments to article. In this example, there are two comments link to article.

Many to Many

For a many-to-many relationship, such as between the Article and Book models, create a “books” field in the Article model and an “articles” field in the Book model. Link the two models using Content Link fields and enable “Allow multiple fields” for both fields to create a many-to-many relationship.


When accessing the data through the API, use the populate=-1 parameter to access all linked content.

2 Likes