Index: /elixir/trunk/CHANGES
===================================================================
--- /elixir/trunk/CHANGES (revision 447)
+++ /elixir/trunk/CHANGES (revision 448)
@@ -9,5 +9,5 @@
   subclasses. For example, this makes it possible to have all classes
   inheriting from your custom base class use some custom options without
-  having to set it individually on each entity, nor modify 
+  having to set it individually on each entity, nor modify
   options.options_defaults.
 - The local_colname and remote_colname arguments on ManyToMany relationships
@@ -81,4 +81,6 @@
 - Fixed filter argument on OneToMany relationship leaking the filter to the
   unfiltered relationship.
+- Fixed using to_dict with a ManyToOne relationship in the "deep" set and that
+  relationship being None in the entity being converted.
 
 0.6.1 - 2008-08-18
Index: /elixir/trunk/elixir/entity.py
===================================================================
--- /elixir/trunk/elixir/entity.py (revision 443)
+++ /elixir/trunk/elixir/entity.py (revision 448)
@@ -1035,5 +1035,7 @@
             fks = self.mapper.get_property(rname).remote_side
             exclude = [c.name for c in fks]
-            if isinstance(dbdata, list):
+            if dbdata is None:
+                data[rname] = None
+            elif isinstance(dbdata, list):
                 data[rname] = [o.to_dict(rdeep, exclude) for o in dbdata]
             else:
Index: /elixir/trunk/tests/test_dict.py
===================================================================
--- /elixir/trunk/tests/test_dict.py (revision 361)
+++ /elixir/trunk/tests/test_dict.py (revision 448)
@@ -26,10 +26,17 @@
         tbl1 = ManyToOne(Table1)
 
-    setup_all(True)
+    setup_all()
 
 def teardown():
-    cleanup_all(True)
+    cleanup_all()
 
 class TestDeepSet(object):
+    def setup(self):
+        create_all()
+
+    def teardown(self):
+        session.close()
+        drop_all()
+
     def test_set_attr(self):
         t1 = Table1()
@@ -88,5 +95,5 @@
         session.commit()
         try:
-            t1.from_dict(dict(tbl2s=[{'t2id':t2.t2id+1}]))
+            t1.from_dict(dict(tbl2s=[{'t2id': t2.t2id+1}]))
             assert False
         except:
@@ -97,7 +104,21 @@
         assert t1.to_dict() == {'t1id': 50, 'name': 'test1'}
 
+    def test_to_deep_m2o(self):
+        t1 = Table1(t1id=1, name='test1')
+        t2 = Table2(t2id=1, name='test2', tbl1=t1)
+        session.flush()
+        assert t2.to_dict(deep={'tbl1': {}}) == \
+               {'t2id': 1, 'name': 'test2', 'tbl1_t1id': 1,
+                'tbl1': {'name': 'test1'}}
+
+    def test_to_deep_m2o_none(self):
+        t2 = Table2(t2id=1, name='test2')
+        session.flush()
+        assert t2.to_dict(deep={'tbl1': {}}) == \
+               {'t2id': 1, 'name': 'test2', 'tbl1_t1id': None, 'tbl1': None}
+
     def test_to_deep(self):
         t1 = Table1(t1id=51, name='test2')
-        assert t1.to_dict(deep={'tbl2s':{}}) == \
+        assert t1.to_dict(deep={'tbl2s': {}}) == \
                 {'t1id': 51, 'name': 'test2', 'tbl2s': []}
 
@@ -116,5 +137,5 @@
         t1.tbl3 = Table3(t3id=50, name='wobble')
         session.commit()
-        assert t1.to_dict(deep={'tbl3':{}}) == \
+        assert t1.to_dict(deep={'tbl3': {}}) == \
                 {'t1id': 53,
                  'name': 'test2',
