On 6/2/15 12:59 PM, Richard Gerd Kuesters wrote:
thanks again Mike!
almost there. the problem now are inherited tables ...
taken from my example code, let's say I have a table that inherits
SomeOtherClass; then, the error is something like:
sqlalchemy.exc.ArgumentError: Index 'ix_adapter_created_on' is against
table 'adapter', and cannot be associated with table 'http_adapter'.
in the example above, http_error inherits from adapter.
take a look at using has_inherited_table(), the section in
http://docs.sqlalchemy.org/en/rel_1_0/orm/extensions/declarative/mixins.html#controlling-table-inheritance-with-mixins
has clues
best regards,
richard.
On 06/02/2015 01:45 PM, Mike Bayer wrote:
On 6/2/15 12:05 PM, Richard Gerd Kuesters wrote:
oh, sorry Mike, I forgot to mention that I use TimestampMixin in
other classes aswell, so I got an "existent index error" (something
like that). Is there a way I don't need to declare the index name?
(IMHO this appears to be the problem).
indexes have to be named something so you'd have to figure out a
naming convention based on tables/column names. There should be an
existing convention for indexes so if you set "None" as the name it
should make one up for you like "ix_tablename_columnname"
thanks a lot!
richard.
On 06/02/2015 12:28 PM, Mike Bayer wrote:
On 6/2/15 10:16 AM, Richard Gerd Kuesters wrote:
hi all, again :)
how can I create an index in fields inherited by other classes?
example:
class TimestampMixin(object):
updated_on = Column(DateTime) # i wanted to create three
indexes in this field, "updated_on", "updated_on.asc()" and
"updated_on.desc()"
class SomeOtherClass(Base, TimestampMixin):
__tablename__ = 'some_table'
id = Column(Integer)
....
Index('ix_some_other_class_01', SomeOtherClass.updated_on)
Index('ix_some_other_class_02', SomeOtherClass.updated_on.asc())
Index('ix_some_other_class_03', SomeOtherClass.updated_on.desc())
I just want to avoid repetition, if possible :)
you could use a __table_args__() callable with @declared_attr. Or
use a mapping event like __declare_first__() or __declare_last__()
(these are hooked into the before_configured / after_configured
events which you could also use directly, e.g.
http://docs.sqlalchemy.org/en/rel_1_0/orm/events.html?highlight=before_configure#sqlalchemy.orm.events.MapperEvents.before_configured)
best regards,
richard.
--
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]
<mailto:[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/d/optout.
--
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]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
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]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
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]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
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]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.
--
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/d/optout.