On Wednesday 27 May 2009, Mark Ramm wrote:
> Also, you can bind the metadata:
>
> http://www.sqlalchemy.org/docs/04/metadata.html#metadata_tables_binding
>
> The disadvantage is that you can't change the engine dynamically once
> the metadata is bound, but that may not be an issue for you.
>

After toying around with this for a couple of hours, here is what I came up 
with:

The problem is basically a "chicken or the egg" problem. The model is imported 
before the engine is initialized, but in order to bind the metadata I'd need 
the engine before the model is imported...
 
I now moved the engine init up in load_environment, right before the auth init 
but after the basic config is initialized (did that with a copy of 
load_environment in config/environment.py)
In app_cfg.py I moved all the config settings that need the model into a 
function, including the import model. That function is now called after the 
engine is initialized just like the model.init_model was called (with the 
engine as parameter which now goes into base_config to make it available in 
the model)

So basically I delayed all model specific setup until everything else is set 
up. The advantage is that now when the model is first imported, the engine is 
already set up.
Now I can reflect tables at the end of model/__init__.py and then just import 
the mapped classes afterwards.

It's a ugly hack and I don't know if there are any negative side effects, but 
it seems to work just fine
Is there a reason why the model is initialized before pretty much anything 
else? Wouldn't it be a point of consideration to generally initialize the 
model after the engine is initialized?

Uwe

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to