so, here i am again with another weird question, but it may be
interesting for what it may come (i dunno yet).
the problem: i have a collection of abstract classes that, when
"requested", the function (that does the request) checks in a internal
dictionary if that class was already created or creates it by using
"declarative_base(cls=MyAbstractClass)", that later can have an engine
and then work against a database.
i use this format because i work with multiple backends from multiple
sources, so abstract classes are a *must* here. now, the problem:
foreign keys and relationships. it's driving me nuts.
ok, let's say I have 2 classes, Foo and Bar, where Bar have one FK to Foo.
class Foo(object):
__abstract__ = True
foo_id = Column(...)
...
class Bar(object):
__abstract__ = True
foo_id = Column(ForeignKey(...))
....
/(those classes are just examples and weren't further coded because it's
a conceptual question)/
i know that the code might be wrong, because i can use @declared_attr
here and furthermore help sqlalchemy act accordingly (i don't know if
this is the right way to say it in english, but it is not a complain
about sqlalchemy actions).
ok, suppose I created two subclasses, one from each abstract model (Foo
and Bar) in a postgres database with some named schema, let's say "sc1".
we then have "sc1.foo" and "sc1.bar".
now, i want to create a third table, also from Bar, but in the "sc2"
schema, where its foreign key will reference "sc1.foo", which postgres
supports nicely.
how can i work this out, in a pythonic and sqlalchemy friendly way? does
@declared_attr solves this? or do I have to map that foreign key (and
furthermore relationships) in the class mapper, before using it, like a
@classmethod of some kind?
best regards and sorry for my english,
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.