I am getting the following error when defining a one-to-many relationship
using the following code:

db = create_engine('postgres://postgres:[EMAIL PROTECTED]/eCommerce')

metadata = BoundMetaData(db)
mapperFactory = MapperFactory(metadata)

ProductAward, ProductAwardTable = mapperFactory('ProductAward', schema='public') ProductFAQAreaUsedFor, ProductFAQAreaUsedForTable = mapperFactory('ProductFAQAreaUsedFor')

ProductFAQArea, ProductFAQAreaTable= mapperFactory('ProductFAQArea', properties={ 'faq_used_for' : relation(ProductFAQAreaUsedFor),
                                   })

ProductFAQ, ProductFAQTable = mapperFactory('ProductFAQ', properties={
                           'faq_area' : relation(ProductFAQArea),
                        })

ProductScreenshot, ProductScreenshotTable = mapperFactory('ProductScreenshot')

ProductInformation, ProductInformationTable = mapperFactory('ProductInformation',
                   properties={
                       'faqs' : relation(ProductFAQ, backref='pi'),
                       'awards' : relation(ProductAward, backref='pi'),
'screenshots' : relation(ProductScreenshot, backref='pi')
                   })



The MapperFactory implementation looks like this:

def myStr(cls):
   return '%s' % (cls.__name__,)


class MapperFactory(object):

   def __init__(self, metadata):
       self.metadata = metadata

   def __call__(self, s, schema=None, properties={}):
       table = Table(s, self.metadata, schema=schema, autoload=True)
       newCls = new.classobj(s, (object,), {})
       newCls.__str__ = classmethod(myStr)
       newCls.__repr__ = classmethod(myStr)
       mapper(newCls, table, properties=properties)
       return newCls, table

Note that the first MapperFactory is called with schema='public'. As soon as you define a table with schema != None I am running into this error. Is there any way out (especially when you have to deal with different schemas)?

Andreas
-----------------


python2.4 07_shop2.py
Traceback (most recent call last):
 File "07_shop2.py", line 33, in ?
product = session.query(ProductInformation).select_by(SAPMaterialNumber='09172-0500')[0] File "build/bdist.macosx-10.3-i386/egg/sqlalchemy/orm/session.py", line 203, in query File "build/bdist.macosx-10.3-i386/egg/sqlalchemy/orm/mapper.py", line 1470, in class_mapper File "build/bdist.macosx-10.3-i386/egg/sqlalchemy/orm/mapper.py", line 259, in compile File "build/bdist.macosx-10.3-i386/egg/sqlalchemy/orm/mapper.py", line 279, in _compile_all File "build/bdist.macosx-10.3-i386/egg/sqlalchemy/orm/mapper.py", line 509, in _initialize_properties File "build/bdist.macosx-10.3-i386/egg/sqlalchemy/orm/interfaces.py", line 39, in init File "build/bdist.macosx-10.3-i386/egg/sqlalchemy/orm/properties.py", line 223, in do_init sqlalchemy.exceptions.ArgumentError: Error determining primary and/or secondary join for relationship 'awards' between mappers 'Mapper|ProductInformation|ProductInformation' and 'Mapper|ProductAward|ProductAward'. If the underlying error cannot be corrected, you should specify the 'primaryjoin' (and 'secondaryjoin', if there is an association table present) keyword arguments to the relation() function (or for backrefs, by specifying the backref using the backref() function with keyword arguments) to explicitly specify the join conditions. Nested error is "Table 'public.ProductAwardType' not defined"

Attachment: pgpLGy0HRXl6E.pgp
Description: PGP signature

Reply via email to