'Test resolution of duplicate inner/left joins'

@unittest.skipIf((not current.deployment_settings.has_module('project')), 'project    module    disabled')
def testPreferredSet(self):

    s3db = current.s3db
    assertEqual = self.assertEqual
    ptable = s3db.project_project
    ltable = s3db.project_task_project
    ttable = s3db.project_task
    ptable_join = ptable.on((ltable.project_id == ptable.id))
    ltable_join = ltable.on((ltable.task_id == ttable.id))
    ijoins = S3Joins('project_task')
    ijoins.extend({'project_project': [ptable_join, ltable_join]})
    ljoins = S3Joins('project_task')
    ljoins.extend({'project_task_project': [ltable_join]})
    tablenames = ['project_project', 'project_task_project']
    join = ijoins.as_list(tablenames=tablenames, prefer=ljoins)
    left = ljoins.as_list(tablenames=tablenames)
    assertEqual(join, [])
    assertEqual(len(left), 2)
    assertEqual(str(left[0]), str(ltable_join))
    assertEqual(str(left[1]), str(ptable_join))
