Simplify merging of entities in preloader

A single merge algorithm for both has and belongs_to associations. Only
the match function, that matches an entity with its associated entity,
is different for the two types of associations now.