A mapping that joins two sources
What this example shows
How a single target entity is filled from more than one source - the join, the condition that drives it, and how the two sources are kept in order.
It is the end state of Creating a Mapping with Multiple Sources.
Branch: examples → mapping → with-multiple-sources
What changed
Everything from the mapping with an expression, plus a Product
entity and a Product mapping that combines two source objects:
sources:
- id: ProductSource
entity: JuiceERP.Product
join: from
- id: PhysicalProductSource
entity: JuiceERP.PhysicalProduct
join: left-join
dependencies:
- ProductSource
conditions:
- ProductSource.ProductID = PhysicalProductSource.ProductID
How multiple sources fit together
join gives each source a role. Exactly one source is the from; the rest join onto it.
Here PhysicalProductSource is a left-join, so products without a physical counterpart still
appear in the result - a deliberate choice, since JuiceERP also has digital products.
dependencies declares what a source needs before it can be joined. PhysicalProductSource
depends on ProductSource, which is what lets CrossModel order the joins correctly. In a mapping
with three or more sources, this is what stops the generated SQL referencing a table before it
has been introduced.
conditions is the join predicate, written in terms of source object ids rather than table
names - the same {{…}}-free reference style used throughout mappings.
Relationships can supply the condition for you
From v1.4.0 a dependency can point at a relationship instead of a hand-written condition. CrossModel then derives the join conditions from that relationship and shows them as read-only rows. If the two source objects are already related in the model, prefer that - the condition stays correct when the relationship changes. This example uses an explicit condition, which is what you need when no relationship exists between the two sources.
What to look at
- The mapping diagram. Two source objects on the left feeding one target. This is the shape worth recognising: integration logic is visible as structure, not buried in SQL.
- The Dependencies grid. Open
PhysicalProductSourcefrom the mapping's Sources grid to see its Source and Relationship columns, and the condition below.
Where to go next
- Do it yourself - Creating a Mapping with Multiple Sources,
starting from the
tutorials→mapping→with-multiple-sourcesbranch - See the join rendered as SQL - Generating data warehouse views