Commits

Mike Bayer committed 603e1d6

modified last commit; the eager loader only undefers columns from the primary mapped table.

Comments (0)

Files changed (3)

lib/sqlalchemy/orm/strategies.py

             for col in sql_util.find_columns(clauses.primaryjoin):
                 if localparent.mapped_table.c.contains_column(col):
                     context.primary_columns.append(col)
-                else:
-                    context.secondary_columns.append(col)
                 
             if self.order_by is False and clauses.alias.default_order_by() is not None:
                 context.eager_order_by += clauses.alias.default_order_by()

test/orm/eager_relations.py

         })
         mapper(User, users, properties={'addresses':relation(Address, lazy=False)})
 
-        assert [User(id=7, addresses=[Address(id=1)])] == create_session().query(User).filter(User.id==7).options(eagerload('addresses')).all()
+        assert [User(id=7, addresses=[Address(id=1)])] == create_session().query(User).filter(User.id==7).all()
 
-        assert [User(id=7, addresses=[Address(id=1)])] == create_session().query(User).limit(1).filter(User.id==7).options(eagerload('addresses')).all()
+        assert [User(id=7, addresses=[Address(id=1)])] == create_session().query(User).limit(1).filter(User.id==7).all()
+
+        sess = create_session()
+        u = sess.query(User).get(7)
+        def go():
+            assert u.addresses[0].user_id==7
+        # assert that the eager loader didn't have to affect 'user_id' here
+        # and that its still deferred
+        self.assert_sql_count(testbase.db, go, 1)
+        
+        clear_mappers()
+        
+        mapper(User, users, properties={'addresses':relation(Address, lazy=False)})
+        mapper(Address, addresses, properties={
+            'user_id':deferred(addresses.c.user_id),
+            'dingalings':relation(Dingaling, lazy=False)
+        })
+        mapper(Dingaling, dingalings, properties={
+            'address_id':deferred(dingalings.c.address_id)
+        })
+        sess = create_session()
+        def go():
+            u = sess.query(User).limit(1).get(8)
+            assert User(id=8, addresses=[Address(id=2, dingalings=[Dingaling(id=1)]), Address(id=3), Address(id=4)]) == u
+        self.assert_sql_count(testbase.db, go, 1)
         
     def test_many_to_many(self):
 

test/testlib/fixtures.py

 class Item(Base):pass
 class Keyword(Base):pass
 class Address(Base):pass
+class Dingaling(Base):pass
 
 metadata = MetaData()
 
     Column('user_id', None, ForeignKey('users.id')),
     Column('email_address', String(50), nullable=False))
 
+dingalings = Table("dingalings", metadata, 
+    Column('id', Integer, primary_key=True),
+    Column('address_id', None, ForeignKey('addresses.id')),
+    Column('data', String(30))
+    )
+    
 items = Table('items', metadata, 
     Column('id', Integer, primary_key=True),
     Column('description', String(30), nullable=False)
         dict(id = 4, user_id = 8, email_address = "ed@lala.com"),
         dict(id = 5, user_id = 9, email_address = "fred@fred.com"),
     )
+    dingalings.insert().execute(
+        dict(id=1, address_id=2, data='ding 1/2'),
+        dict(id=2, address_id=5, data='ding 2/5'),
+    )
     orders.insert().execute(
         dict(id = 1, user_id = 7, description = 'order 1', isopen=0, address_id=1),
         dict(id = 2, user_id = 9, description = 'order 2', isopen=0, address_id=4),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.