On 6 Aug 2006, at 21:31, Robin Munn wrote: > On 8/6/06, Graham Higgins wrote: >> I've been working on a test for many_to_many ... should I >> post it here, on the trac or is more detail required? > Posting (complete) tests here has been the usual pattern.
Thanks (again) Robin. > Michael Bayer has been (incredibly, IMHO) responsive to bug reports > on the > list. I agree. Okay, here goes: There's no existing test for the activemapper many_to_many relationship, I have based the syntax on Kevin Danghoor's code for the TurboGears quickstart template: http://tinyurl.com/qqt48. I am experiencing exactly the same issue with the TG quickstart code, so I assume that I have got the metadata/objectstore housekeeping correct. This is a complete test file and, if copied to test/ext/ activemappertest.py, can be run from that directory as: python test/ ext/activemappertest.py --dburi="postgres://[EMAIL PROTECTED]/test" activemappertest.py =============== import testbase from sqlalchemy.ext.activemapper import ActiveMapper, column, many_to_many, objectstore from sqlalchemy import and_, or_, clear_mappers, backref from sqlalchemy import ForeignKey, String, Integer, Table, Column from datetime import datetime import sqlalchemy.ext.activemapper as activemapper class testmanytomany(testbase.PersistTest): def setUpAll(self): global secondarytable, foo, baz secondarytable = Table("secondarytable", activemapper.metadata, Column("foo_id", Integer, ForeignKey ("foo.id"),primary_key=True), Column("baz_id", Integer, ForeignKey ("baz.id"),primary_key=True)) secondarytable.tometadata(activemapper.metadata) class foo(activemapper.ActiveMapper): class mapping: name = column(String(30)) bazrel = many_to_many('baz', secondarytable, backref='foorel') class baz(activemapper.ActiveMapper): class mapping: name = column(String(30)) foorel = many_to_many("foo", secondarytable, backref='bazrel') activemapper.metadata.connect(testbase.db) activemapper.create_tables() # Create a couple of activemapper objects def create_objects(self): return foo(name='foo1'), baz(name='baz1') def tearDownAll(self): clear_mappers() activemapper.drop_tables() def testbasic(self): # Set up activemapper objects foo1, baz1 = self.create_objects() objectstore.flush() objectstore.clear() # Just checking ... assert (foo1.name == 'foo1') assert (baz1.name == 'baz1') # Diagnostics ... # import sys # sys.stderr.write("\nbazrel missing from dir(foo1):\n%s\n" % dir(foo1)) # sys.stderr.write("\nbazrel in foo1 relations:\n%s\n" % foo1.relations) # Optimistically based on activemapper one_to_many test, try to append # baz1 to foo1.bazrel - (AttributeError: 'foo' object has no attribute 'bazrel') foo1.bazrel.append(baz1) assert (foo1.bazrel == [baz1]) if __name__ == '__main__': testbase.main() Obviously, I will need to do more work on this before it's an adequate test of many_to_many but it's enough to demonstrate the problem (I hope). Cheers, Graham Higgins. ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users