I have 3 models: OrderTypeA(order_id), OrderTypeB(order_id), Invoice(invoice_id, invoice_order_type, invoice_order_id) . Are there any ways to define relationships between OrderTypeA and Invoice, OrderTypeB and Invoice via pair (order_id, invoice_order_id) with additional condition (order_type_id)? Can anyone help me resolve this?