Hey there,

sorry I just re-read all that, guess the coffee didnt kick in yet,
ignore my answer please :P
I misread the UnboundException thingy, so my answers was totally useless.

On Fri, Sep 18, 2009 at 12:33 PM, Crusty <[email protected]> wrote:
> Hey there Lukasz,
>
> you need to import all that into your mymodel.py of course.
>
> from [your_project_here].model import DeclarativeBase, DBSession, metadata
>
> then metadata is bound. I dont know what this has to do with
> "autoload" but your exception complains about metadata being unbound.
> Also I would suggest you to go with declarative syntax, if you dont
> really need the flexibility of a non declarative setup.
>
> Actually if you had really copied the model template, this would be
> all in your file already, so I'm a bit surprised.
> After youre done in mymodel.py you simply import it in
> /models/__init__.py, at the bottom of the file like so:
>
> from mymodel import Recall
>
> Hope I didnt misunderstand your problem.
>
> Greetings,
>
> Tom
>
> On Fri, Sep 18, 2009 at 5:47 AM, Lukasz Szybalski <[email protected]> wrote:
>>
>> Hello,
>>
>>
>> In tg2.
>>
>> cp model.template mymodel.py
>>
>> Inside I put what? If I do this then system complains about:
>>
>> recall_table = Table('recall_db', metadata, autoload=True)
>>
>> class Recall(object):
>>    def __init__(self, **kw):
>>        """automatically mapping attributes"""
>>        for key, value in kw.iteritems():
>>            setattr(self, key, value)
>>
>> #Mapping of Table to Python Object Class
>> mapper(Recall, recall_table)
>>
>> and the bottom of the __init__.py says:
>> from myapp.model.mymodel import Recall
>>
>> That doesn work because:
>>
>> sqlalchemy.exc.UnboundExecutionError: The MetaData is not bound to an
>> Engine or Connection.  Execution can not proceed without a database to
>> execute against.  Either execute with an explicit connection or assign
>> the MetaData's .bind to enable implicit execution.
>>
>>
>> So I read in __init__
>>
>> def init_model(engine):
>>    """Call me before using any of the tables or classes in the model."""
>>
>>    DBSession.configure(bind=engine)
>>    # If you are using reflection to introspect your database and create
>>    # table objects for you, your tables must be defined and mapped inside
>>    # the init_model function, so that the engine is available if you
>>    # use the model outside tg2, you need to make sure this is called before
>>    # you use the model.
>>
>>    #
>>    # See the following example:
>>
>>    #global t_reflected
>>
>>    #t_reflected = Table("Reflected", metadata,
>>    #    autoload=True, autoload_with=engine)
>>
>>    #mapper(Reflected, t_reflected)
>>
>>
>> But what does that mean???
>> Where did Reflected came from??
>> How should I use get my model imported so it stays in the mymodel.py
>> file and the __init__ only imports it.?
>>
>> Ideas?
>>
>> Thanks,
>> Lucas
>>
>> >>
>>
>

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