I'd like to map a class onto table and automatically get __init__() method
per
http://docs.sqlalchemy.org/en/rel_1_0/orm/extensions/declarative/api.html#sqlalchemy.ext.declarative.declarative_base.params.constructor
However when I declare class as
Base = declarative_base(metadata=metadata)
class MyClass(Base):
pass
I get
sqlalchemy.exc.InvalidRequestError: Class <class 'MyClass'> does not have a
__table__ or __tablename__ specified and does not inherit from an existing
table-mapped class.
Is there a way to hold off this check until after I map this class like this
my_table = sa.Table("my_table", meta.metadata, autoload=True,
autoload_with=engine)
orm.mapper(MyClass, my_table)
?
I tried having MyClass inherit from object instead of Base but then I get
TypeError: __init__() got an unexpected keyword argument 'col1'
when calling
x = MyClass(col1=1, col2=2)
, although "my_table" has "COL1" column. So it seems in this case
__init__() method is not automatically synthesized.
Regards,
Piotr
--
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.