Skip to content

adding deferred or other column properties to a declarative class #1379

Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot
Collaborator

Migrated issue, originally created by Michael Bayer (@zzzeek)

patch:

Index: lib/sqlalchemy/ext/declarative.py
===================================================================
--- lib/sqlalchemy/ext/declarative.py	(revision 5902)
+++ lib/sqlalchemy/ext/declarative.py	(working copy)
@@ -552,6 +552,12 @@
                 _undefer_column_name(key, value)
                 cls.__table__.append_column(value)
                 cls.__mapper__.add_property(key, value)
+            elif isinstance(value, ColumnProperty):
+                for col in value.columns:
+                    if isinstance(col, Column) and col.table is None:
+                        _undefer_column_name(key, col)
+                        cls.__table__.append_column(col)
+                cls.__mapper__.add_property(key, value)
             elif isinstance(value, MapperProperty):
                 cls.__mapper__.add_property(key, _deferred_relation(cls, value))
             else:

Activity

sqlalchemy-bot

sqlalchemy-bot commented on Apr 15, 2009

@sqlalchemy-bot
CollaboratorAuthor

Anonymous wrote:

minimal test:

Index: test/ext/declarative.py
===================================================================
--- test/ext/declarative.py	(revision 5912)
+++ test/ext/declarative.py	(working copy)
@@ -4,7 +4,7 @@
 from sqlalchemy import exc
 from testlib import sa, testing
 from testlib.sa import MetaData, Table, Column, Integer, String, ForeignKey, ForeignKeyConstraint, asc, Index
-from testlib.sa.orm import relation, create_session, class_mapper, eagerload, compile_mappers, backref, clear_mappers, polymorphic_union
+from testlib.sa.orm import relation, create_session, class_mapper, eagerload, compile_mappers, backref, clear_mappers, polymorphic_union, deferred
 from testlib.testing import eq_
 from orm._base import ComparableEntity, MappedTest
 
@@ -1243,6 +1243,27 @@
                 Engineer(name='vlad'), Engineer(name='wally')
             ]
         )
+
+    def test_add_deferred(self):
+        class Person(Base, ComparableEntity):
+            __tablename__ = 'people'
+            id = Column('id', Integer, primary_key=True)
+
+        Person.name = deferred(Column(String(10)))
+
+        Base.metadata.create_all()
+        sess = create_session()
+        p = Person(name='ratbert')
+
+        sess.add(p)
+        sess.flush()
+        sess.expunge_all()
+        eq_(
+            sess.query(Person).all(),
+            [               Person(name='ratbert')
+            ](
+)
+        )
         
         
 def produce_test(inline, stringbased):
sqlalchemy-bot

sqlalchemy-bot commented on Apr 18, 2009

@sqlalchemy-bot
CollaboratorAuthor

Michael Trier (@empty) wrote:

Fixed in 7bb91d0. Thank you Scott.

sqlalchemy-bot

sqlalchemy-bot commented on Apr 18, 2009

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Trier (@empty):

  • removed labels: orm
  • added labels: ext
  • changed milestone from "0.5.xx" to "0.5.4"
  • changed status to closed
added
bugSomething isn't working
sqlalchemy.extextension modules, most of which are ORM related
on Nov 27, 2018
added this to the 0.5.4 milestone on Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsqlalchemy.extextension modules, most of which are ORM related

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sqlalchemy-bot

        Issue actions

          adding deferred or other column properties to a declarative class · Issue #1379 · sqlalchemy/sqlalchemy