On Feb 9, 2012, at 1:42 PM, Chris Withers wrote:

> Hi Again,
> 
> I'm wondering if the use case I have is one that is supported...
> 
> So, the situation is that I have a bunch of classes that I need to map to a 
> bunch of tables, and I'd prefer to do that declaratively. The spicey bit is 
> that I need to connect to several environments a lot of the time and not all 
> of these tables are available in all environments.
> 
> So, my plan is to have one engine per database I connect to.
> But what to do about tables?

So what does it mean for your application to import a module, that has a class 
"MyClass", which should be mapped to a table, but when the app is running, that 
table essentially doesn't exist ?  Does that render "MyClass" useless and if so 
why import it ?  Otherwise, if it is still useful, and I'm guessing you're 
using the declared reflection recipe, you'd need to enhance the usage of 
prepare() such that the class is not actually mapped, since there is no table.  
 Or you do something else.     This is all doable.

> 
> Am I right in thinking that I should have one MetaData object per engine, and 
> that MetaData object should only have the tables in it that are actually 
> present in that database?
> 
> If so, what's the recommended pattern for doing that?

Check this post, read the section "Model Setup":

http://techspot.zzzeek.org/2012/01/11/django-style-database-routers-in-sqlalchemy/


> 
> Now, what about declarative? Declarative seems to like each class to have a 
> MetaData object, but how do I tie that in with multiple engines and some 
> tables not being present in some engines?
> 
> What about the declarative registry? I guess having only one of those is fine 
> since it just maps a string name to a class object, right?

its all there, yup

-- 
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