Hi Asher,
the connection between document if Base entry field in the line of the documents.
the base type is according to the base document. ODLN for example is object number 15.
you can find the list in SDK
please seethe query:
select *
from OINV T0 inner join INV1 T1 on T0.DocEntry=T1.DocEntry
left join DLN1 T2 on T1.BaseEntry=T2.DocEntry and T1.BaseType=15
shachar