fix query generation for one-to-one relations

I'm not sure if this is the correct way to do this, but it seems to have fixed the problem for me. There are a couple of tests not passing, but they weren't passing even before this change.