]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- add a migration note for ref #3222
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 10 Oct 2014 00:54:19 +0000 (20:54 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 10 Oct 2014 00:54:19 +0000 (20:54 -0400)
doc/build/changelog/changelog_10.rst
doc/build/changelog/migration_10.rst

index 60dea05649a0583399056f552097f62e39241d43..5b0362c440e12bdbf44c9f2e5876613486fd641f 100644 (file)
 
         This is sort of in-between feature and bug.
 
+        .. seealso::
+
+            :ref:`migration_3222`
+
     .. change::
         :tags: feature, sql
         :tickets: 3184
index b3e5f6f1521a40ed2918f49a18a700561caebc2b..a3b0c03086ee109f005cc54b8163bd132f0ccca1 100644 (file)
@@ -576,6 +576,67 @@ Renders::
 :ticket:`3177`
 
 
+.. _migration_3222:
+
+
+single-table-inheritance criteria added to all ON clauses unconditionally
+-------------------------------------------------------------------------
+
+When joining to a single-table inheritance subclass target, the ORM always adds
+the "single table criteria" when joining on a relationship.  Given a
+mapping as::
+
+    class Widget(Base):
+        __tablename__ = 'widget'
+        id = Column(Integer, primary_key=True)
+        type = Column(String)
+        related_id = Column(ForeignKey('related.id'))
+        related = relationship("Related", backref="widget")
+        __mapper_args__ = {'polymorphic_on': type}
+
+
+    class FooWidget(Widget):
+        __mapper_args__ = {'polymorphic_identity': 'foo'}
+
+
+    class Related(Base):
+        __tablename__ = 'related'
+        id = Column(Integer, primary_key=True)
+
+It's been the behavior for quite some time that a JOIN on the relationship
+will render a "single inheritance" clause for the type::
+
+    s.query(Related).join(FooWidget, Related.widget).all()
+
+SQL output::
+
+    SELECT related.id AS related_id
+    FROM related JOIN widget ON related.id = widget.related_id AND widget.type IN (:type_1)
+
+Above, because we joined to a subclass ``FooWidget``, :meth:`.Query.join`
+knew to add the ``AND widget.type IN ('foo')`` criteria to the ON clause.
+
+The change here is that the ``AND widget.type IN()`` criteria is now appended
+to *any* ON clause, not just those generated from a relationship,
+including one that is explicitly stated::
+
+    # ON clause will now render as
+    # related.id = widget.related_id AND widget.type IN (:type_1)
+    s.query(Related).join(FooWidget, FooWidget.related_id == Related.id).all()
+
+As well as the "implicit" join when no ON clause of any kind is stated::
+
+    # ON clause will now render as
+    # related.id = widget.related_id AND widget.type IN (:type_1)
+    s.query(Related).join(FooWidget).all()
+
+Previously, the ON clause for these would not include the single-inheritance
+criteria.  Applications that are already adding this criteria to work around
+this will want to remove its explicit use, though it should continue to work
+fine if the criteria happens to be rendered twice in the meantime.
+
+:ticket:`3222`
+
 .. _bug_3188:
 
 ColumnProperty constructs work a lot better with aliases, order_by