Ejemplo n.º 1
0
    def object_level_definitions(cls):  # pylint: disable=no-self-argument
        """Set up a backref so that we can create an object level custom
       attribute definition without the need to do a flush to get the
       assessment id.

      This is used in the relate_ca method in hooks/assessment.py.
    """
        cad = custom_attribute_definition.CustomAttributeDefinition
        current_type = cls.__name__

        def join_expr():
            return sa.and_(
                orm.foreign(orm.remote(cad.definition_id)) == cls.id,
                cad.definition_type == utils.underscore_from_camelcase(
                    current_type),
            )

        # Since there is some kind of generic relationship on CAD side, correct
        # join expression for backref should be provided. If default, every call of
        # "{}_definition".format(definition_type) on CAD will produce a lot of
        # unnecessary DB queries returning nothing.
        def backref_join_expr():
            return orm.remote(cls.id) == orm.foreign(cad.definition_id)

        return db.relationship(
            "CustomAttributeDefinition",
            primaryjoin=join_expr,
            backref=db.backref(
                "{}_definition".format(
                    utils.underscore_from_camelcase(current_type)),
                lazy="joined",
                primaryjoin=backref_join_expr,
            ),
            cascade="all, delete-orphan",
        )
Ejemplo n.º 2
0
 def children(cls):
   return db.relationship(
       cls.__name__,
       backref=db.backref('parent', remote_side='{0}.id'.format(cls.__name__)),
       )
Ejemplo n.º 3
0
 def children(cls):  # pylint: disable=no-self-argument
   return db.relationship(
       cls.__name__,
       backref=db.backref(
           'parent', remote_side='{0}.id'.format(cls.__name__)),
   )
Ejemplo n.º 4
0
 def children(cls):  # pylint: disable=no-self-argument
     return db.relationship(
         cls.__name__,
         backref=db.backref('parent',
                            remote_side='{0}.id'.format(cls.__name__)),
     )
Ejemplo n.º 5
0
 def children(cls):
     return db.relationship(
         cls.__name__,
         backref=db.backref('parent',
                            remote_side='{0}.id'.format(cls.__name__)),
     )