> -----Original Message-----
> From: sqlalchemy@googlegroups.com 
> [mailto:sqlalch...@googlegroups.com] On Behalf Of camlost
> Sent: 09 February 2009 09:18
> To: sqlalchemy
> Subject: [sqlalchemy] classes in separate files
> 
> 
> Hi, could someone advice me, please, how to split classes into
> individual files?
> I'm studying the documentation:
> Creating Table, Class and Mapper All at Once Declaratively
> <http://www.sqlalchemy.org/docs/05/ormtutorial.html#creating-table-
> class-and-mapper-all-at-once-declaratively>.
> If I keep all the classes in the same file, the program works fine.
> If I try to split them into individual files, I'm getting errors like
> NoReferencedTableError: Could not find table 'users' with which to
> generate a foreign key
> 
> Are there some "Best practices" of how to do this?
> 
> Thanks.
> 
> c.
> 
> PS: All the classes are in their individual modules in a package
> called database:
> database
>   /dbinit.py - common initialization (ex. Base = declarative_base())
>   /mailevt.py - class MailEvent
>   /mailogrec.py - class MailLogEvent (foreign keys to Server,
> ObjAddress, MailEvent)
>   /objaddr.py - class ObjAddress
>   /server.py - class Server
>   /user.py - class User
>   /useraddr.py - class UserAddress (foreign key to User, ObjAddress)
>   /vpnlogrec.py - class VpnLogRecord (foreign key to User, Server)
>   /weblogrec.py - class WebLogRecord (foreign key to User, Server)

Are all your classes using the same declarative_base? I think this is
necessary so that the tables use the same metadata and things like
foreign keys can be resolved.

I would probably do this by creating database/base.py that contains
something like:

from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()

And then your other modules would import Base from there. Does that make
any sense?

Simon

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to