Hi,

When autoloading table metadata from sqlite database, I have confronted an error. Foreign key definition for column is not reflected in table's foreign_keys property, foreign_key property of the related contains a ForeignKey class reference though. This causes errors when creating associated mapper which also creates one to many relation regarding the problem ForeignKey. If one appends column.foreign key to the table.foreign_keys, mapper can be created as in the example below.

from sqlalchemy import *

engine = create_engine("sqlite://filename=trial.db")

master = Table( "MASTER", engine, autoload=True)
detail = Table("DETAIL", engine, autoload=True)
# DETAIL table contains a column definition like this:
#   MASTER_ID integer references MASTER(ID),

class Master(object):
   pass
class Detail(object):
   pass
detail.foreign_keys.append(detail.c.MASTER_ID.foreign_key)

# below command gives error
#   "Cant find any foreign key relationships between 'MASTER'
#   (<sqlalchemy.schema.Table object at 0x01FDBE30>) and 'DETAIL'
#   (<sqlalchemy.schema.Table object at 0x01FDBED0>)" if the line
#   above is commented
# on the other hand gives
#   "AttributeError: parent" if uncommented.
#
# If all is entered from the intepreter, the line below gives no
# error if the command above is uncommented but the details property
# is not created
#
Master.mapper = mapper(Master, master, properties={
       "details": relation(Detail, detail)
       }
   )
Am I doing something wrong?

Regards,

Murat Ozsoyler



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to