Allow for custom primary keys

Using .id notation will break with models that use custom primary keys. I changed where necessary to use .pk notation.