Re: [sqlalchemy] Having SA generate constructor when using autoload.
On Monday, August 22, 2016 at 12:54:27 PM UTC+2, Simon King wrote: > > > You'd probably be best off copying the SQLAlchemy code into your own > project - it's not long: > > > https://bitbucket.org/zzzeek/sqlalchemy/src/5145f671a4b5eb072e996bc450d2946d4be2a343/lib/sqlalchemy/ext/declarative/base.py?at=master=file-view-default#base.py-634 > > Thank you for pointing me to the right place in source. -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] Having SA generate constructor when using autoload.
On Mon, Aug 22, 2016 at 10:12 AM, Piotr Dobrogostwrote: > 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 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. > You'd probably be best off copying the SQLAlchemy code into your own project - it's not long: https://bitbucket.org/zzzeek/sqlalchemy/src/5145f671a4b5eb072e996bc450d2946d4be2a343/lib/sqlalchemy/ext/declarative/base.py?at=master=file-view-default#base.py-634 Simon -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
[sqlalchemy] Having SA generate constructor when using autoload.
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 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.