'Ensure that DBRef items in ListFields are dereferenced.'

def test_list_item_dereference_dref_false(self):

    class User(Document, ):
        name = StringField()
    class Group(Document, ):
        members = ListField(ReferenceField(User, dbref=False))
    User.drop_collection()
    Group.drop_collection()
    for i in range(1, 51):
        user = User(name=('user    %s' % i))
        user.save()
    group = Group(members=User.objects)
    group.save()
    group.reload()
    with query_counter() as q:
        self.assertEqual(q, 0)
        group_obj = Group.objects.first()
        self.assertEqual(q, 1)
        [m for m in group_obj.members]
        self.assertEqual(q, 2)
    with query_counter() as q:
        self.assertEqual(q, 0)
        group_obj = Group.objects.first().select_related()
        self.assertEqual(q, 2)
        [m for m in group_obj.members]
        self.assertEqual(q, 2)
    with query_counter() as q:
        self.assertEqual(q, 0)
        group_objs = Group.objects.select_related()
        self.assertEqual(q, 2)
        for group_obj in group_objs:
            [m for m in group_obj.members]
            self.assertEqual(q, 2)
    User.drop_collection()
    Group.drop_collection()
