Fix deleting more than 999 related objects using SQLite.

In SQLite, deleting objects that have more than 999 related objects will fail
with a 'too many SQL variables' error.

Changed related_objects() to fetch objects in batches. Added a new test to check
for this new behavior.