def get_relatives(self, ids_only=False, relationship_ids_only=False, entity_id=None, related_entity_id=None, relationship_definition_keyname=None, reverse_relation=False, entity_definition_keyname=None, full_definition=False, limit=None, only_public=False):
        """
        Get Entity relatives.
        * ids_only, relationship_ids_only - return only respective id's if True; return full info by default (False, False).
          (True, True) is interpreted as (True, False)
        * entity_id - find only relations for these entities
        * related_entity_id - find only relations for these related entities
        * relationship_definition_keyname - find only relations with these relationship types
        * reverse_relation - obsolete. Just give related_entity_id instead of entity_id
        * entity_definition_keyname - find only relations with entities of these entity types
        * full_definition - parameter gets forwarded to Entity.__get_properties
        * limit - MySQL-specific limit
        * only_public - if True then only public entities are fetched, othervise user rights are checked. Also gets forwarded to Entity.__get_properties
        """
        if entity_id:
            if type(entity_id) is not list:
                entity_id = [entity_id]

        if related_entity_id:
            if type(related_entity_id) is not list:
                related_entity_id = [related_entity_id]

        if relationship_definition_keyname:
            if type(relationship_definition_keyname) is not list:
                relationship_definition_keyname = [relationship_definition_keyname]

        if entity_definition_keyname:
            if type(entity_definition_keyname) is not list:
                entity_definition_keyname = [entity_definition_keyname]

        unionsql = ''

        if reverse_relation == True:
            sql = """
                SELECT DISTINCT
                    r.id AS relationship_id,
                    r.entity_id AS id,
                    e.sort,
                    e.created
                FROM
                    entity AS e,
                    relationship AS r,
                    relationship AS rights
                WHERE r.entity_id = e.id
                AND rights.entity_id = e.id
                AND r.is_deleted = 0
                AND rights.is_deleted = 0
                AND e.is_deleted = 0
            """
        else:
            sql = """
                SELECT DISTINCT
                    r.id AS relationship_id,
                    r.related_entity_id AS id,
                    e.sort,
                    e.created
                FROM
                    entity AS e,
                    relationship AS r,
                    relationship AS rights
                WHERE r.related_entity_id = e.id
                AND rights.entity_id = e.id
                AND r.is_deleted = 0
                AND rights.is_deleted = 0
                AND e.is_deleted = 0
            """
            if not ids_only:
                unionsql = """
                    UNION SELECT DISTINCT
                        NULL AS relationship_id,
                        up.entity_id AS id,
                        ue.sort,
                        ue.created
                    FROM
                        property up,
                        entity ue,
                        relationship AS urights
                    WHERE ue.id = up.entity_id
                    AND urights.entity_id = ue.id
                    AND up.is_deleted = 0
                    AND ue.is_deleted = 0
                    AND urights.is_deleted = 0
                """

        if entity_id:
            sql += ' AND r.entity_id IN (%s)' % ','.join(map(str, entity_id))

        if related_entity_id:
            sql += ' AND r.related_entity_id IN (%s)' % ','.join(map(str, related_entity_id))

        if self.__user_id and only_public == False:
            sql += ' AND (rights.related_entity_id = %s AND rights.relationship_definition_keyname IN (\'viewer\', \'expander\', \'editor\', \'owner\') OR e.sharing  IN (\'domain\', \'public\'))' % self.__user_id
        else:
            sql += ' AND e.sharing = \'public\''

        if relationship_definition_keyname:
            sql += ' AND r.relationship_definition_keyname IN (%s)' % ','.join(['\'%s\'' % x for x in relationship_definition_keyname])

        if entity_definition_keyname:
            sql += ' AND e.entity_definition_keyname IN (%s)' % ','.join(['\'%s\'' % x for x in entity_definition_keyname])

        if unionsql:
            sql += unionsql

            if entity_id:
                sql += ','.join(map(str, entity_id)) % ' AND up.value_reference IN (%s)'

            if self.__user_id and only_public == False:
                sql += ' AND (urights.related_entity_id = %s AND urights.relationship_definition_keyname IN (\'viewer\', \'expander\', \'editor\', \'owner\') OR ue.sharing  IN (\'domain\', \'public\'))' % self.__user_id
            else:
                sql += ' AND ue.sharing = \'public\''

            if entity_definition_keyname:
                sql += ' AND ue.entity_definition_keyname IN (%s)' % ','.join(['\'%s\'' % x for x in entity_definition_keyname])

        sql += ' ORDER BY sort, created DESC'

        if limit:
            sql += ' LIMIT %d' % limit

        sql += ';'
        # logging.debug(sql)

        if ids_only == True:
            items = []
            for item in self.db_query(sql):
                items.append(item.get('id'))
        elif relationship_ids_only == True:
            items = []
            for item in self.db_query(sql):
                items.append(item.get('relationship_id'))
        else:
            items = {}
            for item in self.db_query(sql):
                ent = self.__get_properties(entity_id=item.get('id'), full_definition=full_definition, entity_definition_keyname=entity_definition_keyname, only_public=only_public)
                if not ent:
                    continue
                ent = ent[0]
                items.setdefault('%s' % ent.get('label_plural', ''), []).append(ent)
        return items
dataset/ETHPy150Open argoroots/Entu/app/main/db.py/Entity.get_relatives/swapped operands of `%`