fixed issue where references with opposites caused incorrect insert and
update statements