Show
Ignore:
Timestamp:
03/27/07 10:30:56 (8 years ago)
Author:
ged
Message:

- (Hopefully) fixed reflecting has_and_belongs_to_many relationships.

Now, you have to specify at least one of either the local_side or remote_side
argument.

- Changed the approach to reflecting/autoloading belongs_to relationships.

This shouldn't change anything to how it's used but allowed me to factor
some code with has_and_belongs_to_many relationships.

- Fixed wrong field length is autoload test (it is not noticeable with sqlite).
- Use an explicit metaclass for entities, so that people can define their own

base class.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/tests/test_autoload.py

    r82 r93  
    2323animal_table = Table('animal', meta, 
    2424    Column('id', Integer, primary_key=True), 
    25     Column('name', String(15)), 
     25    Column('name', String(30)), 
    2626    Column('color', String(15)), 
    2727    Column('owner_id', Integer, ForeignKey('person.id')), 
     
    4747 
    4848class Person(Entity): 
    49     belongs_to('father', of_kind='Person', colname='father_id') 
     49    belongs_to('father', of_kind='Person') 
    5050    has_many('children', of_kind='Person') 
    5151    has_many('pets', of_kind='Animal', inverse='owner') 
     
    5353    has_and_belongs_to_many('categories', of_kind='Category',  
    5454                            tablename='person_category') 
    55     has_and_belongs_to_many('friends', of_kind='Person', 
    56                             tablename='person_person') 
     55    has_and_belongs_to_many('appreciate', of_kind='Person', 
     56                            tablename='person_person', 
     57                            local_side='person_id1') 
     58    has_and_belongs_to_many('isappreciatedby', of_kind='Person', 
     59                            tablename='person_person', 
     60                            local_side='person_id2') 
    5761 
    5862    def __str__(self): 
     
    153157    def test_autoload_has_and_belongs_to_many_selfref(self): 
    154158        barney = Person(name="Barney") 
    155         homer = Person(name="Homer", friends=[barney]) 
    156         barney.friends.append(homer) 
     159        homer = Person(name="Homer", appreciate=[barney]) 
    157160 
    158161        objectstore.flush() 
     
    162165        barney = Person.get_by(name="Barney") 
    163166 
    164         assert homer in barney.friends 
    165         assert barney in homer.friends 
     167        assert barney in homer.appreciate 
     168        assert homer in barney.isappreciatedby 
    166169 
    167170if __name__ == '__main__': 
    168171    test = TestAutoload() 
    169172    test.setup() 
    170     test.test_autoload() 
     173    test.test_autoload_has_and_belongs_to_many_selfref() 
     174#    test.test_autoload() 
    171175    test.teardown()