'Determine which fields need to be included in the schema
@returns: a list of Field instances'

def fields(self):

    resource = self.resource
    tablename = resource.tablename
    fields = []
    mobile_form = self._form = []
    fnames = set()
    include = fnames.add
    form = self.mobile_form(resource)
    for element in form.elements:
        if isinstance(element, S3SQLField):
            rfield = resource.resolve_selector(element.selector)
            fname = rfield.fname
            if ((rfield.tname == tablename) and (fname not in fnames)):
                fields.append(rfield.field)
                mobile_form.append(fname)
                include(fname)
    if (resource.parent and (not resource.linktable) and (resource.pkey == resource.parent._id.name)):
        fkey = resource.fkey
        if (fkey not in fnames):
            fields.append(resource.table[fkey])
            include(fkey)
    return fields
