
from ggrc import db
from .associationproxy import association_proxy
from .mixins import BusinessObject, Hierarchical

class Section(Hierarchical, BusinessObject, db.Model):
  __tablename__ = 'sections'

  directive_id = db.Column(db.Integer, db.ForeignKey('directives.id'))
  na = db.Column(db.Boolean, default=False, nullable=False)
  notes = db.Column(db.Text)
  control_sections = db.relationship('ControlSection', backref='section')
  controls = association_proxy('control_sections', 'control', 'ControlSection')

  _publish_attrs = [
      'directive',
      'na',
      'notes',
      'control_sections',
      'controls',
      ]
  _update_attrs = [
      'directive',
      'na',
      'notes',
      'controls',
      ]

from ggrc import db
from .associationproxy import association_proxy
from .mixins import BusinessObject, Hierarchical

class Section(Hierarchical, BusinessObject, db.Model):
  __tablename__ = 'sections'

  directive_id = db.Column(db.Integer, db.ForeignKey('directives.id'))
  na = db.Column(db.Boolean, default=False, nullable=False)
  notes = db.Column(db.Text)
  control_sections = db.relationship('ControlSection', backref='section')
  controls = association_proxy('control_sections', 'control', 'ControlSection')

  _publish_attrs = [
      'directive',
      'na',
      'notes',
      'control_sections',
      'controls',
      ]
  _update_attrs = [
      'directive',
      'na',
      'notes',
      'controls',
      ]

  @classmethod
  def eager_query(cls):
    from sqlalchemy import orm

    query = super(Section, cls).eager_query()
    return query.options(
        orm.joinedload('directive'),
        orm.subqueryload_all('control_sections.control'))

Add eager-loaded links for Section
Add eager-loaded links for Section

  
  from ggrc import db
  from .associationproxy import association_proxy
  from .mixins import BusinessObject, Hierarchical
  
  class Section(Hierarchical, BusinessObject, db.Model):
    __tablename__ = 'sections'
  
    directive_id = db.Column(db.Integer, db.ForeignKey('directives.id'))
    na = db.Column(db.Boolean, default=False, nullable=False)
    notes = db.Column(db.Text)
    control_sections = db.relationship('ControlSection', backref='section')
    controls = association_proxy('control_sections', 'control', 'ControlSection')
  
    _publish_attrs = [
        'directive',
        'na',
        'notes',
        'control_sections',
        'controls',
        ]
    _update_attrs = [
        'directive',
        'na',
        'notes',
        'controls',
        ]
+ 
+   @classmethod
+   def eager_query(cls):
+     from sqlalchemy import orm
+ 
+     query = super(Section, cls).eager_query()
+     return query.options(
+         orm.joinedload('directive'),
+         orm.subqueryload_all('control_sections.control'))
+ 
Add eager-loaded links for Section
## Code Before:

from ggrc import db
from .associationproxy import association_proxy
from .mixins import BusinessObject, Hierarchical

class Section(Hierarchical, BusinessObject, db.Model):
  __tablename__ = 'sections'

  directive_id = db.Column(db.Integer, db.ForeignKey('directives.id'))
  na = db.Column(db.Boolean, default=False, nullable=False)
  notes = db.Column(db.Text)
  control_sections = db.relationship('ControlSection', backref='section')
  controls = association_proxy('control_sections', 'control', 'ControlSection')

  _publish_attrs = [
      'directive',
      'na',
      'notes',
      'control_sections',
      'controls',
      ]
  _update_attrs = [
      'directive',
      'na',
      'notes',
      'controls',
      ]
## Instruction:
Add eager-loaded links for Section
## Code After:

from ggrc import db
from .associationproxy import association_proxy
from .mixins import BusinessObject, Hierarchical

class Section(Hierarchical, BusinessObject, db.Model):
  __tablename__ = 'sections'

  directive_id = db.Column(db.Integer, db.ForeignKey('directives.id'))
  na = db.Column(db.Boolean, default=False, nullable=False)
  notes = db.Column(db.Text)
  control_sections = db.relationship('ControlSection', backref='section')
  controls = association_proxy('control_sections', 'control', 'ControlSection')

  _publish_attrs = [
      'directive',
      'na',
      'notes',
      'control_sections',
      'controls',
      ]
  _update_attrs = [
      'directive',
      'na',
      'notes',
      'controls',
      ]

  @classmethod
  def eager_query(cls):
    from sqlalchemy import orm

    query = super(Section, cls).eager_query()
    return query.options(
        orm.joinedload('directive'),
        orm.subqueryload_all('control_sections.control'))
