respect :primary_key in belongs_to/has_many, fixes #9
refactor some gnarly code