'Super component field queries use left joins + distinct'

def testGetQueryJoinsSuperComponentField(self):

    s3db = current.s3db
    assertEqual = self.assertEqual
    assertTrue = self.assertTrue
    resource = s3db.resource('pr_person')
    q = (FS('contact.value') == 'test')
    (joins, distinct) = q._joins(resource)
    assertEqual(joins, {})
    assertTrue(distinct)
    pr_person = resource.table
    pr_contact = s3db.pr_contact
    expected = pr_contact.on(((pr_person.pe_id == pr_contact.pe_id) & (pr_contact.deleted != True)))
    (joins, distinct) = q._joins(resource, left=True)
    assertEqual(joins.keys(), ['pr_contact'])
    assertTrue(isinstance(joins['pr_contact'], list))
    assertEqual(str(joins['pr_contact'][0]), str(expected))
    assertTrue(distinct)
