Re: [sqlalchemy] Remote side backpopulates

2018-08-21 Thread Mike Bayer
On Tue, Aug 21, 2018 at 12:47 PM, Alex Rothberg  wrote:
> Is there any way to declare a "remote side" backpopulates? i.e. where I
> declare a relationship on class A to appear only on class B? I would like
> the relationship only to be available on the remote class but I do not want
> to / cannot modify the code for the remote class.


this is Python, so "code" is just another word for "objects
dynamically created and linked together".  Just add the relationship
as you want:

User.permissions = relationship(Permission)



>
> For example:
>
> class User(Model):
> ...
>
> class Permission(Model):
> user_active = relationship(User, backpopulates_remote='permissions')
>
>
> where the user_active field does not get created on Permission but the
> permissions field does get created on User? This comes up since I end up
> writing:
>
> class Permission(Model):
> user = relationship(User)
> user_active = relationship(User, backref='permissions',
> primary_join=...is_active...)
>
> and I do want the user field on Permission and the permissions field on
> User, but I do not want the user_active, as it is extraneous.
>
> --
> 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 post to this group, send email to sqlalchemy@googlegroups.com.
> 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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] Remote side backpopulates

2018-08-21 Thread Alex Rothberg
Is there any way to declare a "remote side" backpopulates? i.e. where I 
declare a relationship on class A to appear only on class B? I would like 
the relationship only to be available on the remote class but I do not want 
to / cannot modify the code for the remote class.

For example:

class User(Model):
...

class Permission(Model):
user_active = relationship(User, backpopulates_remote='permissions')


where the user_active field does not get created on Permission but the 
permissions field does get created on User? This comes up since I end up 
writing:

class Permission(Model):
user = relationship(User)
user_active = relationship(User, backref='permissions', primary_join=...
is_active...)

and I do want the user field on Permission and the permissions field on 
User, but I do not want the user_active, as it is extraneous.

-- 
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 post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.