Im trying to avoid having to write a full example for you from scratch so if
you could provide everything in one example, both models and where you want
the relationships, with all the columns, we can work from there, thanks.


Adrian <adr...@planetcoding.net> wrote:

> In case it's unclear what exactly I'm trying to do, here's the version with 
> the relationship defined right in the User model that works fine.
> I'd like to do this exact same thing, but somehow define the relationship 
> outside the User model. Preferably by using the normal declarative syntax to 
> define the association table and defining the relationship there.
> 
> # in the User model:
> 
>     favorite_users = db.relationship(
>         'User',
>         secondary=favorite_user_table,
>         primaryjoin=id == favorite_user_table.c.user_id,
>         secondaryjoin=(id == favorite_user_table.c.target_id) & ~is_deleted,
>         lazy=True,
>         backref=db.backref('favorite_of', lazy=True),
>     )
> 
> # the association table:
> favorite_user_table = db.Table(
>     'favorite_users',
>     db.metadata,
>     db.Column(
>         'user_id',
>         db.Integer,
>         db.ForeignKey('users.users.id'),
>         primary_key=True,
>         nullable=False,
>         index=True
>     ),
>     db.Column(
>         'target_id',
>         db.Integer,
>         db.ForeignKey('users.users.id'),
>         primary_key=True,
>         nullable=False
>     ),
>     schema='users'
> )
> 
> -- 
> 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.

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