]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Remove extra "return" statement in orm.ext.declared_attr.cascading examples
authorDmitry Bogun <surabujin@surabujin.org.ua>
Sat, 1 Oct 2016 13:22:06 +0000 (09:22 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 1 Oct 2016 13:27:47 +0000 (09:27 -0400)
Also improves some naming in the examples.

Change-Id: I51e5b1d9a730885aed10e5e6ade2123f5e736359
Pull-request: https://github.com/zzzeek/sqlalchemy/pull/306

doc/build/changelog/migration_10.rst
doc/build/orm/extensions/declarative/mixins.rst
lib/sqlalchemy/ext/declarative/api.py

index f539d8b94479567148db9d0dee2b433fb8674679..56b79c88ae2040436cfe602928d13d2989905dd3 100644 (file)
@@ -163,18 +163,16 @@ is affixed to the base class only, and just inherited from subclasses.
 With :attr:`.declared_attr.cascading`, individual behaviors can be
 applied::
 
-    class HasSomeAttribute(object):
+    class HasIdMixin(object):
         @declared_attr.cascading
-        def some_id(cls):
+        def id(cls):
             if has_inherited_table(cls):
                 return Column(ForeignKey('myclass.id'), primary_key=True)
             else:
                 return Column(Integer, primary_key=True)
 
-            return Column('id', Integer, primary_key=True)
-
-    class MyClass(HasSomeAttribute, Base):
-        ""
+    class MyClass(HasIdMixin, Base):
+        __tablename__ = 'myclass'
         # ...
 
     class MySubClass(MyClass):
index e4acc87500296c2566651f1757f4536e4e95d995..d1ad7a68b961a8c83baaa0c129050b783b029260 100644 (file)
@@ -466,17 +466,15 @@ foreign key.  We can achieve this as a mixin by using the
 function should be invoked **for each class in the hierarchy**, just like
 it does for ``__tablename__``::
 
-    class HasId(object):
+    class HasIdMixin(object):
         @declared_attr.cascading
         def id(cls):
             if has_inherited_table(cls):
-                return Column('id',
-                              Integer,
-                              ForeignKey('person.id'), primary_key=True)
+                return Column(ForeignKey('person.id'), primary_key=True)
             else:
-                return Column('id', Integer, primary_key=True)
+                return Column(Integer, primary_key=True)
 
-    class Person(HasId, Base):
+    class Person(HasIdMixin, Base):
         __tablename__ = 'person'
         discriminator = Column('type', String(50))
         __mapper_args__ = {'polymorphic_on': discriminator}
index 1abd0467e0b40057793b8fe17848690100a19e00..b2e8b5afec8fa8112e90f8f3f41334c80e099558 100644 (file)
@@ -196,19 +196,16 @@ class declared_attr(interfaces._MappedAttribute, property):
         Below, both MyClass as well as MySubClass will have a distinct
         ``id`` Column object established::
 
-            class HasSomeAttribute(object):
+            class HasIdMixin(object):
                 @declared_attr.cascading
-                def some_id(cls):
+                def id(cls):
                     if has_inherited_table(cls):
-                        return Column(
-                            ForeignKey('myclass.id'), primary_key=True)
+                        return Column(ForeignKey('myclass.id'), primary_key=True)
                     else:
                         return Column(Integer, primary_key=True)
 
-                    return Column('id', Integer, primary_key=True)
-
-            class MyClass(HasSomeAttribute, Base):
-                ""
+            class MyClass(HasIdMixin, Base):
+                __tablename__ = 'myclass'
                 # ...
 
             class MySubClass(MyClass):