Thanks Michael, this is the second time you helped me. I ended up creating
a decorator to build a dictionary of models and that has worked well.
def register_model(api=False):
'''Class decorator'''
def add_model(cls):
'''Adds model to dictionary and creates api.'''
__models[cls.__tablename__] = cls
if api:
api_manager.create_api(cls)
return cls
return add_model
Regards,
Brendan
On Thursday, November 14, 2013 11:21:15 PM UTC, Michael Bayer wrote:
>
> if you’re looking for an anonymous class that’s generated on the fly, you
> can take a look at sqlsoup: https://sqlsoup.readthedocs.org/en/latest/
>
>
> On Nov 14, 2013, at 5:56 PM, Brendan Condon
> <[email protected]<javascript:>>
> wrote:
>
> I am using sqlalchemy 0.9 and flask / flask-sqlalchemy.
>
> I want to pass in the name of a table and an id and get back the object.
> I use reflection to get the table object, but can't seem to a way to get
> from the table object to the mapped object. I feel like I am missing
> something basic, but I have not been able to find a solution. I appreciate
> your help.
>
> Regards,
>
> Brendan
>
> <code>
>
> def get_instance(table_name, instance_id):
>
> db.metadata.bind = db.engine
> table = Table(table_name, db.metadata,
> autoload=True, autoload_with=db.engine)
>
> return table.query.filter(table.id == instance_id).one()
>
> </code>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected]<javascript:>
> .
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.