'Identify the target resource, attach component if necessary
@param r: the S3Request'

def get_target(self, r):

    resource = self.resource
    alias = r.get_vars.get('component')
    if (alias and (alias not in (resource.alias, '~'))):
        if (alias not in resource.components):
            hook = current.s3db.get_component(resource.tablename, alias)
            if hook:
                resource._attach(alias, hook)
        if (alias in resource.components):
            resource = resource.components[alias]
    return resource
