本文整理汇总了Python中sqlalchemy.ext.associationproxy.association_proxy函数的典型用法代码示例。如果您正苦于以下问题:Python association_proxy函数的具体用法?Python association_proxy怎么用?Python association_proxy使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了association_proxy函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_association
def create_association(cls, assoc_table, relationship_name):
"""
Creates a relationship as relationship_name to the assoc_table for each parent
"""
name = cls.__name__
discriminator = name.lower()
association_name = assoc_table.__tablename__
assoc_cls = type( # creates dynamic class
"{cls_name}{assoc_name}".format(
cls_name=name, assoc_name=assoc_table.__name__
), # name, i.e. EmployeeAddressMap
(assoc_table,), # base
dict(__tablename__=None, __mapper_args__={"polymorphic_identity": discriminator}), # attributes
)
setattr(
cls,
relationship_name,
association_proxy(
association_name, relationship_name, creator=lambda obj: assoc_cls(**{relationship_name: obj})
),
)
return relationship(assoc_cls, backref=backref("parent", uselist=False))
开发者ID:dbbaleva,项目名称:ERP-Forwarding,代码行数:25,代码来源:models.py
示例2: InitMapper
def InitMapper( cls, metadata, Parameter, ParameterType, DesignQuantity ):
mapper( cls, inherits = Parameter, polymorphic_identity = ParameterType, properties = {
'_quantity' : relation( DesignQuantity,
collection_class = attribute_mapped_collection('design'))
})
cls.quantity = association_proxy('_quantity', 'quantity', creator = lambda k, v: DesignQuantity( design = k, quantity = v ) )
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:7,代码来源:DesignQuantity.py
示例3: _set_association_proxy
def _set_association_proxy(cls, edge_cls, attr_name, edge_name, direction):
rel = association_proxy(
edge_name,
direction,
creator=lambda node: edge_cls(**{direction: node})
)
setattr(cls, attr_name, rel)
开发者ID:NCI-GDC,项目名称:psqlgraph,代码行数:7,代码来源:node.py
示例4: declare_categorizable
def declare_categorizable(cls, category_type, single, plural, ation):
setattr(
cls, plural,
association_proxy(
ation, 'category',
creator=lambda category: Categorization(
category_id=category.id,
category_type=category.__class__.__name__,
categorizable_type=cls.__name__
)
)
)
joinstr = (
'and_('
'foreign(Categorization.categorizable_id) == {type}.id, '
'foreign(Categorization.categorizable_type) == "{type}", '
'foreign(Categorization.category_type) == "{category_type}"'
')'
)
joinstr = joinstr.format(type=cls.__name__, category_type=category_type)
backref = '{type}_categorizable_{category_type}'.format(
type=cls.__name__,
category_type=category_type,
)
return db.relationship(
'Categorization',
primaryjoin=joinstr,
backref=backref,
cascade='all, delete-orphan',
)
开发者ID:Smotko,项目名称:ggrc-core,代码行数:31,代码来源:categorization.py
示例5: tag_association
def tag_association(cls):
discriminator = cls.__name__.lower()
creator = TagAssociation.creator(discriminator)
kwargs = {"creator": creator, "getset_factory": _default_list_getset}
cls.tags = associationproxy.association_proxy("tag_association", "tags", **kwargs)
backref = orm.backref("%s_parent" % discriminator, uselist=False)
return orm.relationship("TagAssociation", backref=backref)
开发者ID:quadewarren,项目名称:quark-rackerlabs,代码行数:7,代码来源:models.py
示例6: InitMapper
def InitMapper( cls, metadata, Parameter, ParameterType, ResourceQuantity ):
mapper( cls, inherits = Parameter, polymorphic_identity = ParameterType, properties = {
'_quantity' : relation( ResourceQuantity,
collection_class = attribute_mapped_collection('resource'))
})
cls.quantity = association_proxy('_quantity', 'quantity', creator = lambda k, v: ResourceQuantity( resource = k, **v ) )
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:7,代码来源:ResourceQuantity.py
示例7: transaction_meta_factory
def transaction_meta_factory(self):
"""
Creates TransactionMeta class.
"""
class TransactionMeta(
self.declarative_base,
TransactionMetaBase
):
__tablename__ = 'transaction_meta'
TransactionMeta.transaction_log = sa.orm.relationship(
self.transaction_log_cls,
backref=sa.orm.backref(
'meta_relation',
collection_class=attribute_mapped_collection('key')
),
primaryjoin=(
'%s.id == TransactionMeta.transaction_id' %
self.transaction_log_cls.__name__
),
foreign_keys=[TransactionMeta.transaction_id]
)
self.transaction_log_cls.meta = association_proxy(
'meta_relation',
'value',
creator=lambda key, value: TransactionMeta(key=key, value=value)
)
return TransactionMeta
开发者ID:FelixLoether,项目名称:sqlalchemy-continuum,代码行数:30,代码来源:manager.py
示例8: _categorizations
def _categorizations(cls, rel_name, proxy_name, scope):
setattr(cls, proxy_name, association_proxy(
rel_name, 'category',
creator=lambda category: Categorization(
category=category,
#FIXME add from http session!
modified_by_id=1,
categorizable_type=cls.__name__,
),
))
joinstr = 'and_(foreign(Categorization.categorizable_id) == {type}.id, '\
'foreign(Categorization.categorizable_type) == "{type}", '\
'Categorization.category_id == Category.id, '\
'Category.scope_id == {scope})'
joinstr = joinstr.format(type=cls.__name__, scope=scope)
return db.relationship(
'Categorization',
primaryjoin=joinstr,
backref=BACKREF_NAME_FORMAT.format(type=cls.__name__, scope=scope),
)
# FIXME: make eager-loading work for categorizations/assertations
#@classmethod
#def eager_query(cls):
# from sqlalchemy import orm
# query = super(Categorizable, cls).eager_query()
# return query.options(
# orm.subqueryload_all('categorizations.category'),
# orm.subqueryload_all('assertations.category'))
开发者ID:FlowGR,项目名称:ggrc-core,代码行数:30,代码来源:categorization.py
示例9: _gen_array_simple
def _gen_array_simple(cls, props, k, child_cust, p):
table_name = cls.Attributes.table_name
metadata = cls.Attributes.sqla_metadata
# get left (fk) column info
_gen_col = _get_col_o2m(cls, p.left)
col_info = next(_gen_col) # gets the column name
p.left, child_left_col_type = col_info[0] # FIXME: Add support for multi-column primary keys.
child_left_col_name = p.left
# get right(data) column info
child_right_col_type = get_sqlalchemy_type(child_cust)
child_right_col_name = p.right # this is the data column
if child_right_col_name is None:
child_right_col_name = k
# get table name
child_table_name = child_cust.Attributes.table_name
if child_table_name is None:
child_table_name = '_'.join([table_name, k])
if child_table_name in metadata.tables:
child_t = metadata.tables[child_table_name]
assert child_right_col_type is \
child_t.c[child_right_col_name].type.__class__
assert child_left_col_type is \
child_t.c[child_left_col_name].type.__class__
else:
# table does not exist, generate table
child_right_col = Column(child_right_col_name,
child_right_col_type)
_sp_attrs_to_sqla_constraints(cls, child_cust,
col=child_right_col)
child_left_col = next(_gen_col)
_sp_attrs_to_sqla_constraints(cls, child_cust,
col=child_left_col)
child_t = Table(child_table_name , metadata,
Column('id', sqlalchemy.Integer, primary_key=True),
child_left_col, child_right_col)
# generate temporary class for association proxy
cls_name = ''.join(x.capitalize() or '_' for x in
child_table_name.split('_'))
# generates camelcase class name.
def _i(self, *args):
setattr(self, child_right_col_name, args[0])
cls_ = type("_" + cls_name, (object,), {'__init__': _i})
own_mapper(cls_)(cls_, child_t)
props["_" + k] = relationship(cls_)
# generate association proxy
setattr(cls, k, association_proxy("_" + k, child_right_col_name))
开发者ID:buldi,项目名称:spyne,代码行数:57,代码来源:sqlalchemy.py
示例10: fit_association
def fit_association(cls):
discriminator = cls.__name__.lower()
cls.fits= association_proxy(
"fit_association", "fits",
creator=Fit_Association.creator(discriminator)
)
return relationship(Fit_Association,
cascade="all, delete-orphan", backref=backref("%s_analysis" % discriminator,
uselist=False))
开发者ID:jeffalstott,项目名称:research_code,代码行数:9,代码来源:database_classes.py
示例11: has_field_handler
def has_field_handler(entity, name, *args, **kwargs):
if 'through' in kwargs:
setattr(entity, name,
association_proxy(kwargs.pop('through'),
kwargs.pop('attribute', name),
**kwargs))
return
field = Field(*args, **kwargs)
field.attach(entity, name)
开发者ID:Akylas,项目名称:CouchPotatoServer,代码行数:9,代码来源:fields.py
示例12: address_association
def address_association(cls):
discriminator = cls.__name__.lower()
cls.addresses= association_proxy(
"address_association", "addresses",
creator=AddressAssociation.creator(discriminator)
)
return relationship("AddressAssociation",
backref=backref("%s_parent" % discriminator,
uselist=False))
开发者ID:ContextLogic,项目名称:sqlalchemy,代码行数:9,代码来源:discriminator_on_association.py
示例13: meta_association
def meta_association(cls):
discriminator = cls.__name__.lower()
cls.metas = association_proxy(
"meta_association", "metas",
creator=MetaAssociation.creator(discriminator)
)
return relationship("MetaAssociation",
backref=backref("%s_parent" % discriminator,
uselist=False))
开发者ID:prizm-labs,项目名称:makerspace,代码行数:9,代码来源:models.py
示例14: variable_association
def variable_association(cls):
name = cls.__name__
discriminator = name.lower()
# Defines a polymorphic class to distinguish variables stored
# for regions, cells, etc.
cls.variable_assoc_cls = assoc_cls = type(
"%sVariableAssociation" % name,
(VariableAssociation,),
{
'__tablename__': None, # because mapping into a shared table
'__mapper_args__': {
'polymorphic_identity': discriminator
}
})
def _assoc_creator(kv):
assoc = assoc_cls()
for key, value in kv.items():
assoc.variables[key] = Variable(key=key, value=value)
return assoc
cls._variables = association_proxy(
'variable_association', 'variables', creator=_assoc_creator)
# Using a composite associative proxy here enables returning the
# underlying values for a given key, as opposed to the
# Variable object; we need both.
cls.variables = association_proxy(
'variable_association', 'values', creator=_assoc_creator)
def with_characteristic(self, key, value):
return self._variables.any(key=key, value=value)
cls.with_characteristic = classmethod(with_characteristic)
rel = relationship(
assoc_cls,
collection_class=attribute_mapped_collection('key'),
cascade='all, delete-orphan', lazy='joined',
single_parent=True,
backref=backref('parent', uselist=False))
return rel
开发者ID:sigmavirus24,项目名称:craton,代码行数:44,代码来源:models.py
示例15: handler
def handler(entity, name, *args, **kwargs):
if 'through' in kwargs and 'via' in kwargs:
setattr(entity, name,
association_proxy(kwargs.pop('through'),
kwargs.pop('via'),
**kwargs))
return
elif 'through' in kwargs or 'via' in kwargs:
raise Exception("'through' and 'via' relationship keyword "
"arguments should be used in combination.")
rel = target(kwargs.pop('of_kind'), *args, **kwargs)
rel.attach(entity, name)
开发者ID:brunogola,项目名称:skink,代码行数:12,代码来源:relationships.py
示例16: address_association
def address_association(cls):
discriminator = cls.__name__.lower()
cls.addresses = association_proxy(
'attachment_association', 'attachments',
creator=AddressAssociation.creator(discriminator)
)
return relationship(
'AttachmentAssociation',
backref=sa.orm.backref(
"%s_parent" % discriminator,
uselist=False
)
)
开发者ID:kvesteri,项目名称:flask-alchemy,代码行数:13,代码来源:attachment.py
示例17: address_association
def address_association(cls):
name = cls.__name__
discriminator = name.lower()
assoc_cls = type(
"%sAddressAssociation" % name,
(AddressAssociation,),
dict(__mapper_args__={"polymorphic_identity": discriminator}),
)
cls.addresses = association_proxy(
"address_association", "addresses", creator=lambda addresses: assoc_cls(addresses=addresses)
)
return relationship(assoc_cls, backref=backref("parent", uselist=False))
开发者ID:GitHublong,项目名称:sqlalchemy,代码行数:14,代码来源:discriminator_on_association.py
示例18: object_people
def object_people(cls):
cls.people = association_proxy(
'object_people', 'person',
creator=lambda person: ObjectPerson(
person=person,
modified_by_id=1,
personable_type=cls.__name__,
)
)
joinstr = 'and_(foreign(ObjectPerson.personable_id) == {type}.id, '\
'foreign(ObjectPerson.personable_type) == "{type}")'
joinstr = joinstr.format(type=cls.__name__)
return db.relationship(
'ObjectPerson',
primaryjoin=joinstr,
backref='{0}_personable'.format(cls.__name__),
)
开发者ID:alaeddine10,项目名称:ggrc-core,代码行数:17,代码来源:object_person.py
示例19: object_sections
def object_sections(cls):
cls.sections = association_proxy(
'object_sections', 'section',
creator=lambda section: ObjectSection(
section=section,
sectionable_type=cls.__name__,
)
)
joinstr = 'and_(foreign(ObjectSection.sectionable_id) == {type}.id, '\
'foreign(ObjectSection.sectionable_type) == "{type}")'
joinstr = joinstr.format(type=cls.__name__)
return db.relationship(
'ObjectSection',
primaryjoin=joinstr,
backref='{0}_sectionable'.format(cls.__name__),
cascade='all, delete-orphan',
)
开发者ID:sriharshakappala,项目名称:ggrc-core,代码行数:17,代码来源:object_section.py
示例20: object_controls
def object_controls(cls):
cls.controls = association_proxy(
'object_controls', 'control',
creator=lambda control: ObjectControl(
control=control,
controllable_type=cls.__name__,
)
)
joinstr = 'and_(foreign(ObjectControl.controllable_id) == {type}.id, '\
'foreign(ObjectControl.controllable_type) == "{type}")'
joinstr = joinstr.format(type=cls.__name__)
return db.relationship(
'ObjectControl',
primaryjoin=joinstr,
backref='{0}_controllable'.format(cls.__name__),
cascade='all, delete-orphan',
)
开发者ID:sriharshakappala,项目名称:ggrc-core,代码行数:17,代码来源:object_control.py
注:本文中的sqlalchemy.ext.associationproxy.association_proxy函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论