On Oct 31, 4:03 pm, Evert Rol <[EMAIL PROTECTED]> wrote: > I have a quick question on what to do with the metadata object when > my model definition is spread across several files. It's all in the > same database, all different tables, but for my own logic, I'm > defining parts in different model files. I import the classes then in > the __init__ file, which is imported in the app (controllers) itself. > I'd like to keep the mapping per file, though. Other than that, I'm > following the 'SA 0.4 for people in hurry' by Mike. > So, is that possible, and what do I do with the metdata object? I > would guess that only one call to MetaData() should be enough, or > does it result in the same object anyway? If it's only one call, how > do I get it into the other files?
Here's what I do: Create metadata.py in model with the following (or whatever else you need): from pylons import config from sqlalchemy import Column, MetaData, Table, ForeignKey, types from sqlalchemy.orm import mapper, relation, backref from sqlalchemy.orm import scoped_session, sessionmaker Session = scoped_session(sessionmaker(autoflush=True, transactional=True, bind=config['pylons.g'].sa_engine)) metadata = MetaData() Then I put 'from metadata import *' at the top of each of the model files and 'from metadata import metadata, Session' at the top of __init__.py > As an small additional complication, some classes and tables are > imported from one model file into another, for mapping relations. I'm > now stuck at the point of creating the tables (using 'paster setup- > app'), which complains about a non-existant table from which it needs > a foreign key (table is defined in a different file, but imported for > the relation. My initial guess is, that this is where the metadata > object comes into play). I think I ran into this problem a while ago that I resolved, but I can't recall the details. I'd have to see some sample code. -- Ron --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
