On Thu, Sep 7, 2023, at 4:39 AM, zedr...@gmail.com wrote:
> 
> *Is there a clean way to (programmatically) duplicate all relationship from 
> an existing model, over to a new model (that targets the same table and 
> selects a subset of columns as a subquery)?*

relatonships are fixed to their parent class and have internal state that is 
dependent on it, so it can't be shared between two unrelated classes.

you would need to introspect the attributes of each relationship that are 
important to the application, such as the target class etc., and create a new 
relationship() that has those attributes.    Assuming the relationships dont 
have special join conditions, this would involve just looking for 
existing_class.__mapper__.attrs.relationship.entity, which is the mapper to 
which it refers, and placing this into a new relationship().


> 

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/3c23e775-f2d1-487d-8f5d-e7785399aeba%40app.fastmail.com.

Reply via email to