On 10/23/2016 06:56 AM, Nikola Radovanovic wrote:
Hi,
thank you for the quick reply; I will check this solution. As for number
of clients - clients are actually  companies, so number can be maybe few
dozens, or hundred - does this change anything?

one thing to note is I just checked that recipe for how to use schema_translate_map with orm.Session and I'm not sure it works exactly that way at the moment, apparently there aren't tests to ensure the ORM integration will work that way and I might have to make some changes. There is a way to use it w/ the ORM as in that example but I'd need to give you a recipe for that.

The other is, if you want to stick with your "many models" approach, that is totally fine. You just have those backref issues as you've observed - to get around those you'd need to use a concrete table inheritance pattern which itself can be tedious and intricate in the relationship() department.





Thanks in advance

On Saturday, October 22, 2016 at 2:08:33 PM UTC+2, Nikola Radovanovic wrote:

    Hi all,
    I have a question regarding what will be the best possible way to
    resolve following scenario:

     1. lets say I have table(s) in 'public' schema and multiple
        'private' schemes with same table layout
     2. each private schema is for separate customer, and public
        contains some data everyone may access
     3. clients are dynamic category: i.e some might be added or removed
        during runtime

    There are various relationships (one-to-one, one-to-many and
    many-to-many) for tables/objects in:

     1. same schema and
     2. private and public schemes (but not among privates)

    Basically, I created (virtual) base class for each 'private' object
    and 'generator' class that can create Python class for specific
    client along with proper relationships towards 'public' table(s) and
    'private' tables reside in same schema. Each class is within its own
    python file. There is also a Base class (from declarative_base())
    all objects in my model inherits. When adding a client, I use
    /setattr/ to add relationship property to class

    So, I am wandering:

     1. is this good way to go
     2. I have few classes inherits from db.Model (FLASK app) - will it
        be good idea to switch them also to use same Base object
     3. since I don't know in advance number/names of the clients and
        there are generated Python classes - how does this affects usage
        of metadata to create tables. I noticed troubles with i.e.
        many-to-many when client from public schema try to set backref;
        I got error about multiple definitions in ORM (like it tries to
        add same relationship multiple times)

    Thank You all in advance

--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and
Verifiable Example. See http://stackoverflow.com/help/mcve for a full
description.
---
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 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.

Reply via email to