Add foreign key and join conditions