ManytoMany Associations
As discussed in the chapter Creating Domain Models, LightSpeed represents many‑to‑many associations as through associations. A through association between A and B is implemented using a through entity, which represents an association between one A entity and one B entity. A given A entity may be associated with multiple through entities, each of which links on to one B entity, and vice versa.
The designer provides two ways of presenting through associations. You can choose to show just the many‑to‑many relationship, treating the through entity as an internal implementation detail, which is the most convenient approach in most cases. Or you can choose to show the through entity explicitly, which provides you with fine control and extensibility at the expense of visual clutter.
Using an Auto Through Entity
The first option is referred to as using an auto through entity. Auto through entities avoid cluttering up the diagram when there’s no additional data associated with the relationship, and you don’t need fine control over database mapping, eager loading, etc. To specify an auto through entity, select the through association arrow and enter a name for the through entity in the Auto Through Entity box:
If you have an explicit through entity and it’s not adding any value, you can convert it to an auto through entity by right-clicking the through association and choosing Convert to Auto Through Entity.
Using an Explicit Through Entity
The second option is referred to as using an explicit through entity. In this case the through entity appears on the diagram surface as a fully-fledged entity, allowing you to customise features such as database mapping and eager loading, and to associated extra data with the relationship. For example, suppose you represent tagging by a many‑to‑many association between Contributions and Tags, and you want to record which user applied each Tag to each Contribution. You can’t store that information on the Contribution or the Tag. The best place to store it is therefore on the through entity which represents the contribution–tag association. With an explicit through entity this is easy because you can work with the through entity just like any other entity.
To specify an explicit through entity, select the through association arrow and choose the through entity from the Through Entity drop-down.
When you show an explicit through entity, you must also explicitly model the one-to-many associations between the main entities and the through entity. This allows you to control details such as foreign key column mapping.
If you have an auto through entity and you need to add extra data or fine‑tune the database mapping, you can convert it to an explicit through entity by right-clicking the through association and choosing Convert to Explicit Through Entity.
How Do Auto and Explicit Through Entities Differ?
Fundamentally, they don’t. They result in the same code and the same database schema. They are not different things, just different ways of showing the same thing on the design surface.