341
341
a class which extends :class:`.RelationshipProperty.Comparator` which
342
342
provides custom SQL clause generation for comparison operations.
344
:param distinct_target_key=False:
345
Indicate if a "subquery" eager load should apply the DISTINCT
346
keyword to the innermost SELECT statement. When set to ``None``,
347
the DISTINCT keyword will be applied in those cases when the target
348
columns do not comprise the full primary key of the target table.
349
When set to ``True``, the DISTINCT keyword is applied to the innermost
350
SELECT unconditionally.
352
This flag defaults as False in 0.8 but will default to None in 0.9.
353
It may be desirable to set this flag to False when the DISTINCT is
354
reducing performance of the innermost subquery beyond that of what
355
duplicate innermost rows may be causing.
357
.. versionadded:: 0.8.3 - distinct_target_key allows the
358
subquery eager loader to apply a DISTINCT modifier to the
345
362
docstring which will be applied to the resulting descriptor.
947
964
See the section :ref:`concrete_inheritance` for an example.
966
:param eager_defaults: if True, the ORM will immediately fetch the
967
value of server-generated default values after an INSERT or UPDATE,
968
rather than leaving them as expired to be fetched on next access.
969
This can be used for event schemes where the server-generated values
970
are needed immediately before the flush completes.
971
This scheme will emit an individual ``SELECT`` statement per row
972
inserted or updated, which note can add significant performance
949
975
:param exclude_properties: A list or set of string column names to
950
976
be excluded from mapping.
968
994
is passed automatically as a result of the natural class
969
995
hierarchy of the declared classes.
973
:ref:`inheritance_toplevel`
999
:ref:`inheritance_toplevel`
975
1001
:param inherit_condition: For joined table inheritance, a SQL
976
1002
expression which will
1037
1063
emit an UPDATE statement for the dependent columns during a
1038
1064
primary key change.
1042
:ref:`passive_updates` - description of a similar feature as
1043
used with :func:`.relationship`
1068
:ref:`passive_updates` - description of a similar feature as
1069
used with :func:`.relationship`
1045
1071
:param polymorphic_on: Specifies the column, attribute, or
1046
1072
SQL expression used to determine the target class for an
1129
1155
thus persisting the value to the ``discriminator`` column
1130
1156
in the database.
1134
:ref:`inheritance_toplevel`
1160
:ref:`inheritance_toplevel`
1136
1162
:param polymorphic_identity: Specifies the value which
1137
1163
identifies this particular class as returned by the
1157
1183
can be overridden here.
1159
1185
:param version_id_col: A :class:`.Column`
1160
that will be used to keep a running version id of mapped entities
1161
in the database. This is used during save operations to ensure that
1162
no other thread or process has updated the instance during the
1163
lifetime of the entity, else a
1186
that will be used to keep a running version id of rows
1187
in the table. This is used to detect concurrent updates or
1188
the presence of stale data in a flush. The methodology is to
1189
detect if an UPDATE statement does not match the last known
1164
1191
:class:`~sqlalchemy.orm.exc.StaleDataError` exception is
1165
thrown. By default the column must be of :class:`.Integer` type,
1166
unless ``version_id_generator`` specifies a new generation
1169
:param version_id_generator: A callable which defines the algorithm
1170
used to generate new version ids. Defaults to an integer
1171
generator. Can be replaced with one that generates timestamps,
1176
class MyClass(Base):
1177
__tablename__ = 'mytable'
1178
id = Column(Integer, primary_key=True)
1179
version_uuid = Column(String(32))
1182
'version_id_col':version_uuid,
1183
'version_id_generator':lambda version:uuid.uuid4().hex
1186
The callable receives the current version identifier as its
1193
By default, the column must be of :class:`.Integer` type,
1194
unless ``version_id_generator`` specifies an alternative version
1199
:ref:`mapper_version_counter` - discussion of version counting
1202
:param version_id_generator: Define how new version ids should
1203
be generated. Defaults to ``None``, which indicates that
1204
a simple integer counting scheme be employed. To provide a custom
1205
versioning scheme, provide a callable function of the form::
1207
def generate_version(version):
1212
:ref:`custom_version_counter`
1189
1214
:param with_polymorphic: A tuple in the form ``(<classes>,
1190
1215
<selectable>)`` indicating the default style of "polymorphic"
1196
1221
indicates a selectable that will be used to query for multiple
1201
:ref:`concrete_inheritance` - typically uses ``with_polymorphic``
1202
to specify a UNION statement to select from.
1204
:ref:`with_polymorphic` - usage example of the related
1205
:meth:`.Query.with_polymorphic` method
1226
:ref:`with_polymorphic`
1208
1229
return Mapper(class_, local_table, *args, **params)