def pr_add_affiliation(master, affiliate, role=None, role_type=OU):
 if (not role):
  return None
 master_pe = pr_get_pe_id(master)
 affiliate_pe = pr_get_pe_id(affiliate)
 role_id = None
 if (master_pe and affiliate_pe):
  rtable = current.s3db.pr_role
  query = (((rtable.pe_id == master_pe) & (rtable.role == role)) & (rtable.deleted != True))
  row = current.db(query).select(rtable.id, limitby=(0, 1)).first()
  if (not row):
   data = {'pe_id': master_pe, 'role': role, 'role_type': role_type}
   role_id = rtable.insert(**data)
  else:
   role_id = row.id
  if role_id:
   pr_add_to_role(role_id, affiliate_pe)
 return role_id

def pr_add_affiliation ( master , affiliate , role = None , role_type = OU ) : if ( not role ) : return None master_pe = pr_get_pe_id ( master ) affiliate_pe = pr_get_pe_id ( affiliate ) role_id = None if ( master_pe and affiliate_pe ) : rtable = current . s3db . pr_role query = ( ( ( rtable . pe_id == master_pe ) & ( rtable . role == role ) ) & ( rtable . deleted != True ) ) row = current . db ( query ) . select ( rtable . id , limitby = ( 0 , 1 ) ) . first ( ) if ( not row ) : data = { 'pe_id' : master_pe , 'role' : role , 'role_type' : role_type } role_id = rtable . insert ( ** data ) else : role_id = row . id if role_id : pr_add_to_role ( role_id , affiliate_pe ) return role_id
add a new affiliation record .