~ubuntu-branches/debian/jessie/sqlalchemy/jessie

« back to all changes in this revision

Viewing changes to lib/sqlalchemy/orm/__init__.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski
  • Date: 2013-10-28 22:29:40 UTC
  • mfrom: (1.4.24)
  • Revision ID: package-import@ubuntu.com-20131028222940-wvyqffl4g617caun
Tags: 0.8.3-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
341
341
      a class which extends :class:`.RelationshipProperty.Comparator` which
342
342
      provides custom SQL clause generation for comparison operations.
343
343
 
 
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.
 
351
 
 
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.
 
356
 
 
357
      .. versionadded:: 0.8.3 - distinct_target_key allows the
 
358
         subquery eager loader to apply a DISTINCT modifier to the
 
359
         innermost SELECT.
 
360
 
344
361
    :param doc:
345
362
      docstring which will be applied to the resulting descriptor.
346
363
 
946
963
 
947
964
           See the section :ref:`concrete_inheritance` for an example.
948
965
 
 
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
 
973
          overhead.
 
974
 
949
975
        :param exclude_properties: A list or set of string column names to
950
976
          be excluded from mapping.
951
977
 
968
994
          is passed automatically as a result of the natural class
969
995
          hierarchy of the declared classes.
970
996
 
971
 
          See also:
 
997
          .. seealso::
972
998
 
973
 
          :ref:`inheritance_toplevel`
 
999
            :ref:`inheritance_toplevel`
974
1000
 
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.
1039
1065
 
1040
 
           See also:
 
1066
           .. seealso::
1041
1067
 
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`
1044
1070
 
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.
1131
1157
 
1132
 
          See also:
 
1158
          .. seealso::
1133
1159
 
1134
 
          :ref:`inheritance_toplevel`
 
1160
            :ref:`inheritance_toplevel`
1135
1161
 
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.
1158
1184
 
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
 
1190
           version id, a
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
1167
 
           algorithm.
1168
 
 
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,
1172
 
            uuids, etc. e.g.::
1173
 
 
1174
 
                import uuid
1175
 
 
1176
 
                class MyClass(Base):
1177
 
                    __tablename__ = 'mytable'
1178
 
                    id = Column(Integer, primary_key=True)
1179
 
                    version_uuid = Column(String(32))
1180
 
 
1181
 
                    __mapper_args__ = {
1182
 
                        'version_id_col':version_uuid,
1183
 
                        'version_id_generator':lambda version:uuid.uuid4().hex
1184
 
                    }
1185
 
 
1186
 
            The callable receives the current version identifier as its
1187
 
            single argument.
 
1192
           thrown.
 
1193
           By default, the column must be of :class:`.Integer` type,
 
1194
           unless ``version_id_generator`` specifies an alternative version
 
1195
           generator.
 
1196
 
 
1197
           .. seealso::
 
1198
 
 
1199
              :ref:`mapper_version_counter` - discussion of version counting
 
1200
              and rationale.
 
1201
 
 
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::
 
1206
 
 
1207
              def generate_version(version):
 
1208
                  return next_version
 
1209
 
 
1210
          .. seealso::
 
1211
 
 
1212
             :ref:`custom_version_counter`
1188
1213
 
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
1197
1222
            classes.
1198
1223
 
1199
 
            See also:
1200
 
 
1201
 
            :ref:`concrete_inheritance` - typically uses ``with_polymorphic``
1202
 
            to specify a UNION statement to select from.
1203
 
 
1204
 
            :ref:`with_polymorphic` - usage example of the related
1205
 
            :meth:`.Query.with_polymorphic` method
 
1224
            .. seealso::
 
1225
 
 
1226
              :ref:`with_polymorphic`
1206
1227
 
1207
1228
    """
1208
1229
    return Mapper(class_, local_table, *args, **params)