\**kwargs follow:
- association
- Deprecated; as of version 0.3.0 the association keyword is synonymous
- with applying the "all, delete-orphan" cascade to a "one-to-many"
- relationship. SA can now automatically reconcile a "delete" and
- "insert" operation of two objects with the same "identity" in a flush()
- operation into a single "update" statement, which is the pattern that
- "association" used to indicate.
-
backref
indicates the name of a property to be placed on the related mapper's
class that will handle this relationship in the other direction,
metadata. Use this argument when no ForeignKey's are present in the
join condition, or to override the table-defined foreign keys.
- foreignkey
- deprecated. use the ``foreign_keys`` argument for foreign key
- specification, or ``remote_side`` for "directional" logic.
-
join_depth=None
when non-``None``, an integer value indicating how many levels
deep eagerload joins should be constructed on a self-referring
value is computed based on the foreign key relationships of the parent
and child tables (or association table).
- private=False
- deprecated. setting ``private=True`` is the equivalent of setting
- ``cascade="all, delete-orphan"``, and indicates the lifecycle of child
- objects should be contained within that of the parent.
-
remote_side
used for self-referential relationships, indicates the column or list
of columns that form the "remote side" of the relationship.
properly. If this is the case, use an alternative method.
"""
-
return PropertyLoader(argument, secondary=secondary, **kwargs)
def dynamic_loader(argument, secondary=None, primaryjoin=None, secondaryjoin=None, entity_name=None,
operations are available.
A subset of arguments available to relation() are available here.
- """
+ """
from sqlalchemy.orm.dynamic import DynaLoader
return PropertyLoader(argument, secondary=secondary, primaryjoin=primaryjoin,
passive_deletes=passive_deletes, order_by=order_by,
strategy_class=DynaLoader)
-#def _relation_loader(mapper, secondary=None, primaryjoin=None, secondaryjoin=None, lazy=True, **kwargs):
-
def column_property(*args, **kwargs):
"""Provide a column-level property for use with a Mapper.
An optional instance of [sqlalchemy.orm#PropComparator] which
provides SQL expression generation functions for this composite
type.
- """
+ """
return CompositeProperty(class_, *cols, **kwargs)
Used with the `backref` keyword argument to ``relation()`` in
place of a string argument.
- """
+ """
return BackRef(name, **kwargs)
def deferred(*columns, **kwargs):
table column when first accessed.
Used with the `properties` dictionary sent to ``mapper()``.
- """
+ """
return ColumnProperty(deferred=True, *columns, **kwargs)
def mapper(class_, local_table=None, *args, **params):
that no other thread or process has updated the instance
during the lifetime of the entity, else a
``ConcurrentModificationError`` exception is thrown.
- """
+ """
return Mapper(class_, local_table, *args, **params)
def synonym(name, map_column=False, descriptor=None, proxy=False):
self.kwargs = kwargs
self.prop = _prop
self.extension = attributes.GenericBackrefExtension(self.key)
-
+
def compile(self, prop):
if self.prop:
return
mapper = prop.mapper.primary_mapper()
if mapper._get_property(self.key, raiseerr=False) is None:
- pj = self.kwargs.pop('primaryjoin', None)
- sj = self.kwargs.pop('secondaryjoin', None)
-
+ if prop.secondary:
+ pj = self.kwargs.pop('primaryjoin', prop.secondaryjoin)
+ sj = self.kwargs.pop('secondaryjoin', prop.primaryjoin)
+ else:
+ pj = self.kwargs.pop('primaryjoin', prop.primaryjoin)
+ sj = self.kwargs.pop('secondaryjoin', None)
+ if sj:
+ raise exceptions.InvalidRequestError("Can't assign 'secondaryjoin' on a backref against a non-secondary relation.")
+
parent = prop.parent.primary_mapper()
self.kwargs.setdefault('viewonly', prop.viewonly)
self.kwargs.setdefault('post_update', prop.post_update)
primaryjoin=node.c.id==node.c.parent_id,
lazy=True,
cascade="all",
- backref=backref("parent",
- primaryjoin=node.c.parent_id == node.c.id,
- remote_side=node.c.id)),
+ backref=backref("parent", remote_side=node.c.id)
+ ),
'prev_sibling': relation(
Node,
primaryjoin=node.c.prev_sibling_id==node.c.id,
polymorphic_identity='table1',
properties={
'next': relation(Table1,
- backref=backref('prev', primaryjoin=join.c.id==join.c.related_id, foreignkey=join.c.id, uselist=False),
+ backref=backref('prev', foreignkey=join.c.id, uselist=False),
uselist=False, primaryjoin=join.c.id==join.c.related_id),
'data':relation(mapper(Data, data))
},
polymorphic_identity='table1',
properties={
'next': relation(Table1,
- backref=backref('prev', primaryjoin=table1.c.id==table1.c.related_id, remote_side=table1.c.id, uselist=False),
+ backref=backref('prev', remote_side=table1.c.id, uselist=False),
uselist=False, primaryjoin=table1.c.id==table1.c.related_id),
'data':relation(mapper(Data, data), lazy=False, order_by=data.c.id)
},
master=relation(Assembly,
foreign_keys=[specification_table.c.master_id],
primaryjoin=specification_table.c.master_id==products_table.c.product_id,
- lazy=True, backref=backref('specification', primaryjoin=specification_table.c.master_id==products_table.c.product_id),
+ lazy=True, backref=backref('specification'),
uselist=False),
slave=relation(Product,
foreign_keys=[specification_table.c.slave_id],
master=relation(Assembly, lazy=False, uselist=False,
foreign_keys=[specification_table.c.master_id],
primaryjoin=specification_table.c.master_id==products_table.c.product_id,
- backref=backref('specification', primaryjoin=specification_table.c.master_id==products_table.c.product_id, cascade="all, delete-orphan"),
+ backref=backref('specification', cascade="all, delete-orphan"),
),
slave=relation(Product, lazy=False, uselist=False,
foreign_keys=[specification_table.c.slave_id],
master=relation(Assembly, lazy=False, uselist=False,
foreign_keys=[specification_table.c.master_id],
primaryjoin=specification_table.c.master_id==products_table.c.product_id,
- backref=backref('specification', primaryjoin=specification_table.c.master_id==products_table.c.product_id),
+ backref=backref('specification'),
),
slave=relation(Product, lazy=False, uselist=False,
foreign_keys=[specification_table.c.slave_id],
primaryjoin=sa.and_(pages.c.jobno==pageversions.c.jobno,
pages.c.pagename==pageversions.c.pagename),
order_by=pageversions.c.version,
- backref=backref('page',
- lazy=False,
- primaryjoin=sa.and_(
- pages.c.jobno==pageversions.c.jobno,
- pages.c.pagename==pageversions.c.pagename)))})
+ backref=backref('page',lazy=False)
+ )})
mapper(PageComment, pagecomments, properties={
'page': relation(
Page,
pages.c.pagename==pagecomments.c.pagename),
backref=backref("comments",
cascade="all, delete-orphan",
- primaryjoin=sa.and_(
- pages.c.jobno==pagecomments.c.jobno,
- pages.c.pagename==pagecomments.c.pagename),
order_by=pagecomments.c.comment_id))})
@testing.resolve_artifact_names