sector119 <sector...@gmail.com> wrote:

> Hello!
> 
> I have some model:
> 
> class Person(Base):
>     __tablename__ = 'person'
> 
>     id = Column(BigInteger, primary_key=True, autoincrement=False)
>     locality_id = Column(Integer, ForeignKey(SYSTEM_SCHEMA + '.locality.id'), 
> nullable=False)
>     street_id = Column(Integer, ForeignKey('street.id'), nullable=False)
>     building = Column(Integer, nullable=False)
>     apartment = Column(Integer, nullable=False)
>     ...
> 
> 
> I want to create this model at different schemas: 'schema1', 'schema2', 
> 'schema3' and model's FK street_id should point to 'street.id' at the same 
> schema!
> 
> How can I do that?

this is an ongoing area for people, as there’s different ways to do so-called 
“multi-tenancy” vs. “sharding” etc.   So it sort of depends on what you 
actually need.  Let’s assume you need the different Person classes 
simultaneously, e.g. more of a sharding situation. 

Easiest way is to make a mixin, there’s an example at 
https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/EntityName, second 
one down.

Mixins have gotten a lot better, so you should be able to do what you need.   
There’s even more fixes for mixins in 1.0 that is nearing beta releases.

-- 
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.

Reply via email to