🚀 Welcome to MDriven Learn –  MDriven is now on Discord!  Don’t miss the latest Release Notes.
Embed
This page was created by Henrik on 2018-01-16. Last edited by Wikiadmin on 2026-07-29.

You use the Embed flag on an association end to control where MDriven stores the association reference when it maps your model to tables. This page is for modelers who need to choose the foreign-key direction for an association.

What Embed means

Embed (shown as e on an association end) answers this question: which table contains the foreign key for this association?

A foreign key is a stored reference from one table row to the related row in another table. In most associations, the multiplicity makes the correct location clear. The setting matters most when both ends have multiplicity one.

For example, if one School has many Class objects, each class belongs to one school. The reference to the school is normally stored with each class:

School 1 ---- * Class

In relational terms, the Class table holds a foreign key that identifies its School.

Choose the storage location

Use the association multiplicities first. The following table describes the normal result.

Association shape Normal foreign-key location How Embed affects the choice
One-to-many The table for the many end holds the foreign key. This is normally self-evident. Embed on the many end permits the expected direct storage.
Many-to-many A link class holds the two foreign keys. The link class can be implicit. Neither entity table can hold one foreign key for all links; a link class is required.
One-to-one Either table can hold the foreign key. Choose the embedded end to select the table that stores the reference.

One-to-many example

Consider Order and OrderLine:

Order 1 ---- * OrderLine

An order can have several order lines, while an order line is associated with one order. The OrderLine table is the natural place for the foreign key to Order. This is the usual meaning of embedding the association at the many end.

Many-to-many example

Consider Student and Course:

Student * ---- * Course

A student can take many courses and a course can have many students. MDriven uses a link class to store each student-course pair. If you have not modeled that class explicitly, MDriven can create an implicit association class for the link.

One-to-one example

Consider Person and Passport:

Person 1 ---- 1 Passport

Either Person can store the reference to Passport, or Passport can store the reference to Person. Set Embed on the end that represents the table where you want that foreign key stored.

Set Embed deliberately

Follow this process when you model an association:

  1. Identify the multiplicity at both association ends.
  2. For a one-to-many association, use the many end as the normal foreign-key location.
  3. For a many-to-many association, expect a link class, whether explicit or implicit.
  4. For a one-to-one association, decide which object should store the reference and set Embed on that end.
  5. If you have no storage preference in a one-to-one association, select either end. The association remains valid; the choice determines the table layout.

What happens when Embed is false on a many end

Setting Embed=false on the many end of a one-to-many association prevents MDriven from using the normal direct foreign key in the many-end table.

For example, in School 1 ---- * Class, setting Embed=false on the Class end tells MDriven not to store the school reference in Class. MDriven then assumes that you need a different representation and creates an implicit association class in which it can store the keys.

Do this only when you have a reason not to use the normal foreign-key placement. For ordinary one-to-many relationships, leaving the many end embedded matches the natural relational structure.

Embed is not form embedding

The Embed flag described here controls persistence—the table that stores an association reference. It is not the same as choosing whether an automatically generated form opens in its own document or is displayed inside the current document.

In MDriven Designer autoforms, an association can be configured to render an associated form as Embed in document rather than Own form. That is a user-interface rendering choice. After changing the autoform setting, refresh the model including autoforms so the generated forms reflect the change. See Documentation:Showing data and Documentation:Navigation for related UI topics.

Related modeling concepts

An association can also be derived rather than stored. A derived association is calculated, for example by navigating from a school through its classes to their pupils; it does not replace the storage decision for an ordinary persisted association. Learn more in Documentation:Derived attributes & associations.

See also