Making sure that we handle the case where primary keys are longs.

Apologies for the crappy pull request.

I haven't managed to diagnose this further but this was a quick fix I needed to get an app running on production.

Not really expecting this to be merged in but more an indicator of a problem with a potential fix (didn't decide whether a long was actually wrong or not so just smashed it into an int).