Changeset 448

Show
Ignore:
Timestamp:
03/23/09 11:56:17 (4 years ago)
Author:
ged
Message:

Fixed using to_dict with a ManyToOne relationship in the "deep" set and that
relationship being None in the entity being converted.

Location:
elixir/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/CHANGES

    r447 r448  
    99  subclasses. For example, this makes it possible to have all classes 
    1010  inheriting from your custom base class use some custom options without 
    11   having to set it individually on each entity, nor modify  
     11  having to set it individually on each entity, nor modify 
    1212  options.options_defaults. 
    1313- The local_colname and remote_colname arguments on ManyToMany relationships 
     
    8181- Fixed filter argument on OneToMany relationship leaking the filter to the 
    8282  unfiltered relationship. 
     83- Fixed using to_dict with a ManyToOne relationship in the "deep" set and that 
     84  relationship being None in the entity being converted. 
    8385 
    84860.6.1 - 2008-08-18 
  • elixir/trunk/elixir/entity.py

    r443 r448  
    10351035            fks = self.mapper.get_property(rname).remote_side 
    10361036            exclude = [c.name for c in fks] 
    1037             if isinstance(dbdata, list): 
     1037            if dbdata is None: 
     1038                data[rname] = None 
     1039            elif isinstance(dbdata, list): 
    10381040                data[rname] = [o.to_dict(rdeep, exclude) for o in dbdata] 
    10391041            else: 
  • elixir/trunk/tests/test_dict.py

    r361 r448  
    2626        tbl1 = ManyToOne(Table1) 
    2727 
    28     setup_all(True) 
     28    setup_all() 
    2929 
    3030def teardown(): 
    31     cleanup_all(True) 
     31    cleanup_all() 
    3232 
    3333class TestDeepSet(object): 
     34    def setup(self): 
     35        create_all() 
     36 
     37    def teardown(self): 
     38        session.close() 
     39        drop_all() 
     40 
    3441    def test_set_attr(self): 
    3542        t1 = Table1() 
     
    8895        session.commit() 
    8996        try: 
    90             t1.from_dict(dict(tbl2s=[{'t2id':t2.t2id+1}])) 
     97            t1.from_dict(dict(tbl2s=[{'t2id': t2.t2id+1}])) 
    9198            assert False 
    9299        except: 
     
    97104        assert t1.to_dict() == {'t1id': 50, 'name': 'test1'} 
    98105 
     106    def test_to_deep_m2o(self): 
     107        t1 = Table1(t1id=1, name='test1') 
     108        t2 = Table2(t2id=1, name='test2', tbl1=t1) 
     109        session.flush() 
     110        assert t2.to_dict(deep={'tbl1': {}}) == \ 
     111               {'t2id': 1, 'name': 'test2', 'tbl1_t1id': 1, 
     112                'tbl1': {'name': 'test1'}} 
     113 
     114    def test_to_deep_m2o_none(self): 
     115        t2 = Table2(t2id=1, name='test2') 
     116        session.flush() 
     117        assert t2.to_dict(deep={'tbl1': {}}) == \ 
     118               {'t2id': 1, 'name': 'test2', 'tbl1_t1id': None, 'tbl1': None} 
     119 
    99120    def test_to_deep(self): 
    100121        t1 = Table1(t1id=51, name='test2') 
    101         assert t1.to_dict(deep={'tbl2s':{}}) == \ 
     122        assert t1.to_dict(deep={'tbl2s': {}}) == \ 
    102123                {'t1id': 51, 'name': 'test2', 'tbl2s': []} 
    103124 
     
    116137        t1.tbl3 = Table3(t3id=50, name='wobble') 
    117138        session.commit() 
    118         assert t1.to_dict(deep={'tbl3':{}}) == \ 
     139        assert t1.to_dict(deep={'tbl3': {}}) == \ 
    119140                {'t1id': 53, 
    120141                 'name': 'test2',